FTPPutFile
FTP function.
The FTPPutFile function uploads one or several files from the local PC to a FTP folder.
Syntax
FTPPutFile(<spec_files>,<FTP_foldername> [,<Ascii|Binary> [,<FTP_filename>]])
or
ret=FTPPutFile(<spec_files>,<FTP_foldername> [,<Ascii|Binary> [,<FTP_filename>]])Parameters
<spec_files>, string, name of the file(s) to upload. Wildcard characters are permitted for uploading multiple files.
<FTP_foldername>, string, name of the FTP folder where the files have to be uploaded. If the folder does not exist, it is created. If the files already exist on the FTP folder, they are replaced.
<Ascii|Binary>, optional keyword. The default is Binary. See Remarks section below.
<FTP_filename>, optional parameter, string. Used only if just one file is uploaded. In that case, <FTP_filename> specifies the name under which the file is written on the FTP server. If several files are uploaded, the file names on FTP server are the ones on the local machine. If several files are uploaded and this parameter is given, this parameter is not used. If <FTP_filename> includes by mistake a path, it is not taken into account, the file will be uploaded in <FTP_foldername>.
Return value
Ret, numeric return code. The return code is 0 when the file(s) has been successfully uploaded. 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 upload 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 upload 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!)
FtpPutFile("c:\test\*.jpg","/upgrades/todelete") ' uploads all the *.jpg files stored in local directory c:\test to the FTP folder /upgrades/todelete
FtpDisconnect() ' Terminates the FTP connection
FtpConnect("www.wintask.com","ftp","MX/WH05CZE3h") ' connection to the FTP server www.wintask.com (fake credentials!)
FtpPutFile("C:\test\myimage.jpg","/upgrades/todelete","newimage.jpg") ' uploads myimage.jpg stored in local directory c:\test to FTP folder /upgrades/todelete 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!)
FtpPutFile("C:\test\myimage.jpg","/upgrades/todelete","ASCII","newimage.jpg") ' uploads myimage.jpg stored in local directory c:\test to FTP folder /upgrades/todelete and saves it under the name newimage.jpg. The data are tansferred using ASCII mode.
FtpDisconnect() ' Terminates the FTP connection