Skip to content

Instantly share code, notes, and snippets.

@sarathlal-old
Last active August 29, 2015 14:26
Show Gist options
  • Save sarathlal-old/c506a894ecf2ec834c81 to your computer and use it in GitHub Desktop.
Save sarathlal-old/c506a894ecf2ec834c81 to your computer and use it in GitHub Desktop.
Transfer files from server to server using PHP ftp_put() function
<?php
//Place this file in source server and go to the path
set_time_limit(0); //Unlimited max execution time
$remote_file = '/var/www/file.zip'; //File to be saved in remote server with path
/* FTP Account */
$ftp_host = 'ftp-host.com'; /* host */
$ftp_user_name = 'ftp-username@your-ftp-host.com'; /* username */
$ftp_user_pass = 'ftppassword'; /* password */
/* File name and path for the file to be moved from source server */
$local_file = 'file.zip';
/* Connect using basic FTP */
$connect_it = ftp_connect( $ftp_host );
/* Login to FTP */
$login_result = ftp_login( $connect_it, $ftp_user_name, $ftp_user_pass );
/* Send $local_file to FTP */
if ( ftp_put( $connect_it, $remote_file, $local_file, FTP_BINARY ) ) {
echo "WOOT! Successfully transfer $local_file\n";
}
else {
echo "Doh! There was a problem\n";
}
/* Close the connection */
ftp_close( $connect_it );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment