Upload files from one server to another server using php not working? Upload files from one server to another server using php not working? codeigniter codeigniter

Upload files from one server to another server using php not working?


Thanks for your support guys. I am happy to post this answer couple of days work. Only the thing is need to avoid the destination server path /public_html/test.txt instead of test.txt. If you have any sub folders give like sample/test.txt . Kindly check the below code, it is use full for some one like me.

/* Source File Name and Path */            $remote_file = '/var/www/html/artbak/assets/uploads/edi/test.txt';            $ftp_host = 'hostname'; /* host */            $ftp_user_name = 'username'; /* username */            $ftp_user_pass = 'password'; /* password */             /* New file name and path for this file */            $local_file = 'test.txt';            /* 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_put( $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 );

And one thing is in my server had some firewall block, for that reason only first ftp not connecting via php code. Now i solve that issue also. Because my code working in local to server already know. For that i referred the below link to solve the firewall block in server, Can't connect to FTP with PHP ftp_connect from localhost . So it is working well.