Home > Language Reference > FTP Functions > FTPPutFile

FTPPutFile

The FTPPutFile function uploads the specified file(s) to the FTP server.

Usage

Used to upload data on a FTP server or to backup a complete directory structures on a FTP server.

Syntax

ret=FTPPutFile(<spec_files>,<FTP_foldername> [,Ascii|Binary [,<FTP_filename>])

Parameters

<spec_files>, string, name of the file(s) to upload. Wildcards (* or ?) may be used to upload files matching a certain mask.

<FTP_foldername>, string, destination FTP folder name for the uploaded file(s). If the folder does not exist, it is automatically created at execution. If the uploaded file(s) already exist in the folder, they are replaced.

ASCII or BINARY, optional keyword. The default is BINARY. Specify ASCII if you upload text files and want to use Ascii.

<FTP_filename>, optional string, destination FTP file name for the uploaded file if only one file is uploaded. If this parameter is not specified or if multiple files are uploaded (and in this last case, even if <FTP_filename> is specified), the filenames on the FTP server are the same as on the PC. If <FTP_filename> includes by mistake a path, the path is not considered and the file is written in <FTP_foldername>.

Return value

Ret, optional numeric return value. If the function succeeds uploading the file(s) within 30 seconds, the function returns 0. INCREASE the timeout using #FTPTimeout if the upload takes more than 30 seconds. If the function fails, the return value is a nonzero negative value (see FTP Functions Error Codes).

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.

See also

FTPGetFile

Examples

FtpConnect("www.my_site.com","ftp","MX/WH05CZE3h") ' connection to the FTP server www.my_site.com (fake credentials!)

FtpPutFile("c:\wttest\*.jpg","/upgrades/todelete") ' uploads all the *.jpg files stored in local directory c:\wttest to the FTP folder /upgrades/todelete.
FtpDisconnect() ' Terminates the FTP connection

FtpConnect("
www.my_site.com","ftp","MX/WH05CZE3h") ' connection to the FTP server www.my_site.com (fake credentials!)
FtpPutFile("C:\wttest\myimage.jpg","/upgrades/todelete", , "newimage.jpg") ' uploads myimage.jpg stored in local directory c:\wttest to FTP folder /upgrades/todelete
'and saves it under the name newimage.jpg.
FtpDisconnect() ' Terminates the FTP connection


FtpConnect("
www.my_site.com","ftp","MX/WH05CZE3h") ' connection to the FTP server www.my_site.com (fake credentials!)
FtpPutFile("C:\wttest\myimage.jpg","/upgrades/todelete","ASCII","newimage.jpg") ' uploads myimage.jpg stored in local directory c:\wttest 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