FTPGetFile
FTP function.
The FTPGetFile function downloads one or several files to the local PC from the FTP server.
Syntax
FTPGetFile(<spec_files>,<local_directory_name> [,<Ascii|Binary> [,<local_filename>]])
or
ret=FTPGetFile(<spec_files>,<local_directory_name> [,<Ascii|Binary> [,<local_filename>]])Parameters
<spec_files>, string, name of the file(s) to download. Wildcard characters are permitted for downloading multiple files.
<local_directory_name>, string, name of the local directory where the downloaded files are written. If the directory does not exist, it is created.
<Ascii|Binary>, optional keyword. The default is Binary. See Remarks section below.
<local_filename>, optional parameter, string. If only one file is downloaded from the FTP server, this optional parameter specifies a new name under which the downloaded file is stored on <local_directory_name>. If this parameter is not specified or if multiple files are downloaded (and in this last case, even if <local_filename> is specified), the filenames on the local PC are the same as on the FTP server. If <local_filename> includes by mistake a path, it is not taken into account, the file will be written in <local_directory_name>.
Return value
Ret, numeric return code. The return code is 0 when the file(s) has been successfully downloaded. The non zero possible error codes for FTP errors are listed in FTP functions error codes topic. The non zero possible error codes due to a file error on the PC are listed in File management functions error codes topic. During #FTPTimeout seconds, the function tries to download the file(s) and after this timeout, the standard error management is used.
Remarks
When files are transferred in ASCII mode, the transferred data is considered to contain only ASCII formatted text. The party that is receiving the transferred data is responsible for translating the format of the received text to one that is compatible with their operating system. The most common example of how this is applied pertains to the way Windows and UNIX handle newlines. On a Windows computer, pressing the "enter" key inserts two characters in an ASCII text document - a carriage return (which places the cursor at the beginning of the line) and a line feed (which places the cursor on the line below the current one). On UNIX systems, only a line feed is used. ASCII text formatted for use on UNIX systems does not display properly when viewed on a Windows system and vice versa.
Binary mode refers to transferring files as a binary stream of data. Where ASCII mode may use special control characters to format data, binary mode transmits the raw bytes of the file being transferred. In this way, the file is transferred in its exact original form.
IMPORTANT: increase the value of #FTPTimeout if you download big files to avoid a script timeout during the download.
See also
Examples
FtpConnect("www.wintask.com","ftp","MX/WH05CZE3h") ' connection to the FTP server www.wintask.com (fake credentials!)
FtpGetFile("/upgrades/todelete/*.jpg","C:\test") ' downloads all the *.jpg files stored in upgrades/todelete folder to the local directory c:\test.
FtpDisconnect() ' Terminates the FTP connection
FtpConnect("www.wintask.com","ftp","MX/WH05CZE3h") ' connection to the FTP server www.wintask.com (fake credentials!)
FtpGetFile("/upgrades/todelete/myimage.jpg","C:\test",,"c:\test\newimage.jpg") ' downloads myimage.jpg stored in upgrades/todelete folder to the local directory c:\test and saves it under the name newimage.jpg.
FtpDisconnect() ' Terminates the FTP connection
FtpConnect("www.wintask.com","ftp","MX/WH05CZE3h") ' connection to the FTP server www.wintask.com (fake credentials!)
FtpGetFile("/upgrades/todelete/myimage.jpg","C:\test","ASCII","c:\test\newimage.jpg") ' downloads myimage.jpg stored in upgrades/todelete folder to the local directory c:\test and saves it under the name newimage.jpg. The data are tansferred using ASCII mode.
FtpDisconnect() ' Terminates the FTP connection