FTP Upload File
Like this blog? Consider exploring one of our sponsored banner ads...
Need to transfer files via FTP in some automated or scheduled manner. It is actually quite easy to do using FTP. Following is a simplistic PHP FTP example to get you started.
Replace ‘hostname’, ‘username’, and ‘password’ with real FTP credentials, then we try and connect to the FTP server.
//FTP CONNECT $connect = ftp_connect('hostname'); $login = ftp_login($connect, 'username', 'password');
if an error occurred connecting to the FTP server, then we can stop here:
//CONNECTION ERROR if ((!$connect) || (!$login)) { echo "FTP Connection Failed"; exit; }
Otherwise let’s proceed and upload a file via FTP. Be sure to replace ‘/path/to/file.ext’ with the full path to your file, as well as ‘file.ext’ with the filename you would like to use when you FTP up the file.
//UPLOAD THE FILE $file = fopen('/path/to/file.ext', 'r'); $upload = ftp_fput($connect, 'file.ext', $file, FTP_ASCII); fclose($file); ftp_close($connect);
and finally let’s perform a simple check to see if the file was uploaded successfully.
// UPLOAD ERROR if (!$upload) { echo "FTP Upload Failed"; } // UPLOAD SUCCESS else { echo "FTP Upload Success"; }
About this entry
You’re currently reading “FTP Upload File,” an entry on BRADINO
- Published:
- 12.8.08 / 3pm
- Category:
- PHP
- Tags:
1 Comment
Jump to comment form | comments rss [?]