The DownloadFile method provides a convenient way for an
application to download a file in a single method call. Based on the
connection information specified in the URL, it will connect to the
server, authenticate the session, change the current working
directory if necessary and then download the file to the local
system. The URL must be complete, and specify either a standard or
secure FTP scheme:
[ftp|ftps|sftp]://[username : password] @] remotehost [:remoteport] / [path / ...] [filename] [;type=a|i]
If no user name and password is provided, then the client session
will be authenticated as an anonymous user. If a path is specified as
part of the URL, the method will attempt to change the current
working directory. Note that the path in an FTP URL is relative to
the home directory of the user account and is not an absolute path
starting at the root directory on the server. The URL scheme will
always determine if the connection is secure, not the option. In
other words, if the "ftp" scheme is used and the
FTP_OPTION_SECURE option is specified, that option will be ignored.
To establish a secure connection, either the "ftps" or
"sftp" scheme must be specified.
The optional "type" value at the end of the file name
determines if the file should be downloaded as a text or binary file.
A value of "a" specifies that the file should be downloaded
as a text file. A value of "i" specifies that the file
should be downloaded as a binary file. If the type is not explicitly
specified, the file will be downloaded as a binary file.
The lpStatus parameter can be used by the application to
determine the final status of the transfer, including the total
number of bytes copied, the amount of time elapsed and other
information related to the transfer process. If this information
isn't needed, then this parameter may be specified as NULL.
The lpEventProc parameter specifies a pointer to a
function which will be periodically called during the file transfer
process. This can be used to check the status of the transfer by
calling GetTransferStatus and then update the program's user
interface. For example, the callback function could calculate the
percentage for how much of the file has been transferred and then
update a progress bar control. The dwParam parameter is used
in conjunction with the event handler and specifies a user-defined
value that is passed to the callback function. One common use in a
C++ program is to pass the this pointer as the value, and then
cast it back to an object pointer inside the callback function. If no
event handler is required, then a NULL pointer can be specified as
the value for lpEventProc and the dwParam parameter
will be ignored.
The DownloadFile method is designed to provide a simpler
interface for downloading a file. However, complex connections such
as those using a proxy server or a secure connection which uses a
client certificate will require the program to establish the
connection using Connect and then use GetFile to
download the file.