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


i have tried in many ways upload files using ftp functions in php. not working me. don't know mistake made in code. have given local file path or server file path also, in both cases not working. have given code below. can find problem?

/* source file name , path */ $backup_file = '/var/www/html/artbak/assets/uploads/edi/test.txt'; //$backup_file = '/workspace/all-projects/artbak/assets/uploads/edi/test.txt'; $remote_file = $backup_file;  $ftp_host = 'hostname'; /* host */ $ftp_user_name = 'username'; /* username */ $ftp_user_pass = 'password'; /* password */   /* new file name , path file */ $local_file = '/public_html/example.txt';  /* connect using basic ftp */ $connect_it = ftp_connect( $ftp_host );  /* login ftp */ $login_result = ftp_login( $connect_it, $ftp_user_name, $ftp_user_pass );  /* download $remote_file , save $local_file */ if ( ftp_put( $connect_it, $local_file, $remote_file, ftp_binary ) ) {     echo "woot! written $local_file\n"; } else {     echo "doh! there problem\n"; }  /* close connection */ ftp_close( $connect_it ); 

the below code working local server upload, not working server server upload. shows server not connecting. please give ideas guys. struggling in more in concept.

$ftp_host = 'hostname'; /* host */ $ftp_user_name = 'username'; /* username */ $ftp_user_pass = 'password'; /* password */   // set connection or die $conn_id = ftp_connect($ftp_server) or die("couldn't connect $ftp_server");   // login username , password $login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);  $file = "dummy.txt";  $remote_file = "receivedummy.txt";  // upload file if (ftp_put($conn_id, $remote_file, $file, ftp_ascii)) {     echo "successfully uploaded $file\n"; } else {     echo "there problem while uploading $file\n"; }  // close connection ftp_close($conn_id); 

thanks support guys. happy post answer couple of days work. thing need avoid destination server path /public_html/test.txt instead of test.txt. if have sub folders give sample/test.txt . kindly check below code, use full 1 me.

/* source file name , 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 , path file */             $local_file = 'test.txt';              /* connect using basic ftp */             $connect_it = ftp_connect( $ftp_host );              /* login ftp */             $login_result = ftp_login( $connect_it, $ftp_user_name, $ftp_user_pass );              /* download $remote_file , save $local_file */             if ( ftp_put( $connect_it, $local_file, $remote_file, ftp_binary ) ) {                 echo "woot! written $local_file\n";             }             else {                 echo "doh! there problem\n";             }              /* close connection */             ftp_close( $connect_it ); 

and 1 thing in server had firewall block, reason first ftp not connecting via php code. solve issue also. because code working in local server know. referred below link solve firewall block in server, can't connect ftp php ftp_connect localhost . working well.


Comments