The FTP functions can be used for uploading or downloading files from a web server.
ftp_download(string url, string path, string username, string password)
Starts a file download from a FTP server. Returns 0 if an error occured, nonzero otherwise.
Use ftp_status to check when the transfer was complete.
ftp_upload(string url, string path, string username, string password)
Starts a a file upload to a FTP server. Returns 0 if an error occured, nonzero otherwise. Use
ftp_status to check when the transfer was complete.
ftp_getdate(string url, string username, string password)
Starts a file access for getting the timestamp and size of a file stored on a FTP server.
Returns 0 if an error occured, nonzero otherwise. Use
ftp_status to check when the file access was complete.
Stops the currently running FTP transfer.
Returns the total file size of the current/last file in bytes.
Returns the amount of sent data of the current/last file in bytes.
Returns the timestamp of the current/last file, after ftp_getdate() was executed successfully.
Returns the status of a currently running or the last FTP transfer:
-1 if the last FTP transfer was stopped because of an error
0 if the FTP transfer is still running
1 if the last FTP transfer was successful
ftp_log (var mode)
Enables/disables the logging of FTP transfers. The logfile is named "ftp_log.txt".
url - URL of the file to be downloaded, or destination URL for a file upload (e.g.: "ftp://www.testhoster.com/downloads/test.txt").
path - local path + filename (e.g.: "testdir/test.txt")
username - FTP username
password - FTP password
mode - 1 to enable, 0 to disable FTP logging
- Only one FTP transfer can be run at the same time. After calling ftp_download(), ftp_upload() or ftp_getdate() wait until the value of ftp_status() is nonzero.
- For uploading or downloading to SFTP servers, or for other FTP/SFTP
operations such as creating directories, get
curl.exe and run
it with exec. Example:
exec("C:\\Tools\\curl.exe","-k \"sftp:/myserver.host/upload/\" --user
\"myname:pass\" -T \"Data\\file.txt\" --ftp-create-dirs",1);.
//Downloads the file "myfile.txt" and saves it in the Data folder
while(!ftp_status()) //as long as the download is running
if (ftp_status() == 1)
http functions, file functions,