Xbasic

INET::FTP Class

Description

Class for uploading data using FTP/FTPS(FTP over SSL). For SFTP (FTP over SSH), use INET::SFTP

Example

dim f as inet::ftp
dim ctxt as p
ctxt.SourceFile = "String - 'Fred - xxxxx' "
ctxt.TargetFile = "fred.txt"

statusbar.set_text("Starting test...")

f.host = "kurt64"
f.UserContext = ctxt
f.eventscript = <<%code%
FUNCTION SendBegin as L (FTP as INET::FTP, ExpectedSize as N, BYREF ProgressInterval as N, BYREF Cancel as L)
    ' Turn off progress events.
    'ProgressInterval = 1
    statusbar.set_text("Beginning transfer of " + ftp.usercontext.SourceFile +" to " + ftp.usercontext.TargetFile)
END FUNCTION

FUNCTION SendProgress as L (FTP as INET::FTP, ExpectedSize as N, BytesSent as N, BYREF Cancel as L)
    statusbar.set_text("Transferred " + BytesSent + " of " + ExpectedSize + " from " + ftp.usercontext.SourceFile + " to " + ftp.usercontext.TargetFile)
END FUNCTION

FUNCTION SendCanceled as L (FTP as INET::FTP)
    statusbar.set_text("Canceled transfer of " + ftp.usercontext.SourceFile + " to " + ftp.usercontext.TargetFile)
END FUNCTION

FUNCTION SendCompleted as L (FTP as INET::FTP, SizeSent as N)
    statusbar.set_text("Completed transfer of " + ftp.usercontext.SourceFile + " to " + ftp.usercontext.TargetFile)
END FUNCTION

FUNCTION SendEnd as L (FTP as INET::FTP)
     statusbar.set_text("Ready to send again!")
END FUNCTION
%code%

f.sendstringdata(ctxt.SourceFile, ctxt.TargetFile)
'showvar(f.usercontext)
showvar(f.eventscript + crlf() + "Status" + crlf() + f.callresult.text + crlf() + f.callresult.nativetext, "Done")

Properties

CallResultCallResult

The result of the last call to a method on the FTP class.

HostCharacter

Default = "localhost". The location of the FTP server.

KeepAliveLogical

Default = .f.. Defines whether or not the connection to the FTP server should be closed after the request completes. If .t., connection will remain open. Otherwise, connection will be closed.

UsePassiveLogical

Default = .t.. Gets or sets the behavior of the data transfer process.

EnableSSLLogical

Default = .f.. If .t., FTPS will be used.

RequireValidCertificateLogical

Default = .t.. If set to .t., SSL connections will validate the certificate.

BufferSizeNumeric

Default = 8192. The buffer size to use in transferring files. Performance can be improved on large file transfers by increasing the size of this buffer. Setting the property is optional.

TimeOutNumeric

The number of milliseconds to wait for a request. If no request is received within the specified time frame, the operation is aborted.

UserNameCharacter

The user name for authentication.

PasswordCharacter

The password for authentication.

TotalLengthNumeric

The total length of the file or buffer being sent.

EventScriptCharacter

An Xbasic script that implements one or more functions to respond to the SendBegin, SendProgress, SendCancelled and SendCompleted events. Note that SendBegin and SendProgress pass a flag that can be set to .t. to cancel the transfer. See example above.

UserContextPointer

A reference to an Xbasic object to be passed into event functions. Use this to provide some context for event scripts such as the file requested and the target name.

LengthSentNumeric

The length of data sent so far. Used with the Xbasic event script to display or respond to progress events.

Methods

DeleteFile Method

Remove a file from the server.

ListDirectory Method

Retrieves a directory of files within a folder on the server.

ReceiveBinaryData Method

Receives the contents of a server file into a binary buffer.

ReceiveFile Method

Receive a file from the server. Contents are received as binary unless ReceiveBinary is set to .f.

ReceiveStringData Method

Receive the contents of a server file into a text buffer.

SendBinaryData Method

Send a buffer of binary data to the target file specified.

SendFile Method

Send a file to the server. Contents are sent as binary unless SendBinary is set to .f.

SendStringData Method

Send a buffer of text data to the target file specified.

See Also