FTP Upload
This codesnippet can be used to login into a FTP server, and then upload a file. Common use might be for backup purposes on a off-site FTP server.
// Open FTP connection
$conn_id = ftp_connect($ftp_server);
// Login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// Check the connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// Upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// Check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// Close the FTP connection
ftp_close($conn_id);
?>
March 31st, 2006 at 5:52 pm
Copied from php.net ?
July 24th, 2006 at 8:23 pm
yep, kinda sure he did….