Using PHP FTP to move files from server to server

Sometimes using PHP Copy didn’t work if the files is somehow protected by this method (hotlink protection maybe?). I did experience that if the source is from Hostgator it didn’t work.

But we can use another method. Using FTP (in PHP) to do the transfer using the code:

/**
 * Transfer (Import) Files Server to Server using PHP FTP
 * @link https://shellcreeper.com/?p=1249
 */
 
/* Source File Name and Path */
$remote_file = 'files.zip';
 
/* FTP Account */
$ftp_host = 'your-ftp-host.com'; /* host */
$ftp_user_name = '[email protected]'; /* username */
$ftp_user_pass = 'ftppassword'; /* password */
 
 
/* New file name and path for this file */
$local_file = 'files.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 );
 
/* Download $remote_file and save to $local_file */
if ( ftp_get( $connect_it, $local_file, $remote_file, FTP_BINARY ) ) {
    echo "WOOT! Successfully written to $local_file\n";
}
else {
    echo "Doh! There was a problem\n";
}
 
/* Close the connection */
ftp_close( $connect_it );

About

Website development,php development,wordpress development,joomla development,Symfony development,iOS development,Android development,XHTML designer,HTML5 designer,responsive web design,twitter bootstrap design, hire designer, hire developer

Follow The Author

Leave a Replay

Your email address will not be published. Required fields are marked *

*
*