FTPWI.Download

FTPWI.Download (

string URL,

string Filename,

string Username = "anonymous",

string Password = "guest@",

number Mode = MODE_BINARY,

number Timeout = 20,

number Port = 21,

boolean PassiveMode = true,

function CallbackFunction = nil )

Description

Downloads a file from an FTP site using FTP (file transfer protocol).

Parameters

URL

(string) The full ftp address to the file you want to download. For example, ftp://ftp.myftpsite.com/updates/myfile.txt.

Filename

(string) The destination path and filename of the file you want to download. For example, C:\\MyFolder\\patch.zip.

Username

(string) The name to use to log into the FTP site. The default for anonymous FTP is "anonymous".

Password

(string) The password for the FTP site that goes with the FTP Username. For anonymous FTP, use your email address or the password default "guest@".

Mode

(number) The mode you want to use to save the file. Choose from:

CONSTANT

VALUE

DESCRIPTION

MODE_BINARY

0

Save the file exactly as downloaded. (Default)

MODE_TEXT

1

Convert the file from Unix to Windows text mode, if necessary.

Timeout

(number) The maximum time in seconds that the action will wait for a response after attempting to connect. The default value is 20.

Note: Timeout values are interpreted in multiple ways during client server communication. As a result the actual timeout used by the connection may differ from the value specified.

Port

(number) The port to connect to. In most cases the default value of 21 is standard for FTP.

PassiveMode

(boolean) Use passive/firewall mode when downloading the file. Passive mode (also known as "firewall mode") is required whenever you need to transfer files to or from an FTP server from behind a firewall. Passing the default value true enables passive mode and passing false disables it.

Normally, your computer makes a connection to an FTP server, and the FTP server responds by opening a connection back to your computer. This return connection won't work if your computer can't be reached directly from the Internet. In passive mode, both connections are made from your computer, so the FTP server doesn't have to do any connecting-it just waits passively for your computer to make both of the connections to it.

Most servers support passive mode connections, so it's generally best to leave this setting enabled.

CallbackFunction

(function) The name of a function that will be called whenever progress is made in the download operation. (You can use this callback function to display the progress of the download in your own custom way.)

Note: If CallbackFunction is set to nil, then the progress information will be sent to the built-in status dialog, assuming it is currently visible. (You can show or hide the status dialog with a StatusDlg.Show or StatusDlg.Hide action.)

The callback function must be able to receive the following parameters:

BytesRead

(number) The number of bytes that have been downloaded so far.

FileSize

(number) The file size in bytes or 0 if the file size could not be retrieved from the server.

TransferRate

(number) The current transfer rate in Kilobytes per second.

SecondsLeft

(number) The estimated number of seconds left in the download.

SecondsLeftFormat

(string) The estimated number of seconds left formatted as a string in the form of: ""MM:SS".

Message

(string) Either a blank string ("") or an information message being sent by the server, such as "Resolving host name" or "Connecting to Server."

Note: If this parameter is not a blank string, it means that it is in a busy state, either before the download has begun, or at the end of the download. In this case all other parameters will be ignored.

The callback function should return a boolean value (true or false) indicating whether the download should continue:

VALUE

DESCRIPTION

true

Continue with the file download.

false

Stop the file download as soon as possible.

Returns

Nothing. You can use Application.GetLastError to determine whether this action failed, and why.

See also: Related Actions