am trying to find php script so I can transload files from my server to another server any help ?! Happy Holidays Everyone.. Thanks and regards
Well this can be coded ... upload through FTP ? Here is some code : <?php $user = 'username'; $pass = 'password'; $host = 'hostname'; $port = 21; $localFile = 'localfile.txt'; $remoteFile = 'remotefile.txt'; $con = ftp_connect($host,$port,15) or die('Couldn\'t connect to the required ftp server'); if(@ftp_login($con,$user,$pass)) { if( ftp_put($con,$remoteFile,$localFile,FTP_ASCII) ) { echo 'The file has been successfully uploaded.'; } else { echo 'The file couldn\'t be uploaded !'; } ftp_close($con); } else { echo 'Username or password is wrong !'; ftp_close($con); } ?> PHP:
Thank you for great script, It dose not seems that is supporting large files, got when trying to move a 1 GB file The script able to do this up to 600 MB
Try this then : <?php set_time_limit(0); ini_set('upload_max_filesize','1000M'); ob_start(); $remote_file = 'remote.txt'; $local_file = 'local.txt'; $fp = fopen($local_file, 'r'); $conn_id = ftp_connect($ftp_server); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); $ret = ftp_nb_fput($conn_id, $remote_file, $fp, FTP_BINARY); while ($ret == FTP_MOREDATA) { // Establish a new connection to FTP server if(!isset($conn_id2)) { $conn_id2 = ftp_connect($ftp_server); $login_result2 = ftp_login($conn_id2, $ftp_user_name, $ftp_user_pass); } // Retreive size of uploaded file. if(isset($conn_id2)) { clearstatcache(); // <- this must be included!! $remote_file_size = ftp_size($conn_id2, $remote_file); } // Calculate upload progress $local_file_size = filesize($local_file); if (isset($remote_file_size) && $remote_file_size > 0 ){ $i = ($remote_file_size/$local_file_size)*100; printf("%d%% uploaded<br>", $i); flush(); } $ret = ftp_nb_continue($conn_id); } if ($ret != FTP_FINISHED) { print("There was an error uploading the file...<br>"); exit(1); } else { print("Done.<br>"); } fclose($fp); ob_end_flush(); ?> PHP:
why dont you simply use ftp programs instead? if you are transferring large chances are you might hit the php ini memory limit on either side. still if a necessity tvoodoo solutions look good. Thanks
It's not possible to upload folder but you can zip the folder and upload it. Yes, ftp is good but for large files it's faster to do it direct but if you have bad server it would not work. <?php set_time_limit(0); ini_set('upload_max_filesize','1000M'); ob_start(); // the file on remote http example http://domainname.com/remote.txt $remote_file = 'remote.txt'; // name the file in local example local.txt $local_file = 'local.txt'; $fp = fopen($local_file, 'r'); $conn_id = ftp_connect($ftp_server); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); $ret = ftp_nb_fput($conn_id, $remote_file, $fp, FTP_BINARY); while ($ret == FTP_MOREDATA) { // Establish a new connection to FTP server if(!isset($conn_id2)) { $conn_id2 = ftp_connect($ftp_server); $login_result2 = ftp_login($conn_id2, $ftp_user_name, $ftp_user_pass); } // Retreive size of uploaded file. if(isset($conn_id2)) { clearstatcache(); // <- this must be included!! $remote_file_size = ftp_size($conn_id2, $remote_file); } // Calculate upload progress $local_file_size = filesize($local_file); if (isset($remote_file_size) && $remote_file_size > 0 ){ $i = ($remote_file_size/$local_file_size)*100; printf("%d%% uploaded<br>", $i); flush(); } $ret = ftp_nb_continue($conn_id); } if ($ret != FTP_FINISHED) { print("There was an error uploading the file...<br>"); exit(1); } else { print("Done.<br>"); } fclose($fp); ob_end_flush(); ?> PHP: but where did you declare the username and password and host name and port as old script <?php $user = 'username'; $pass = 'password'; $host = 'hostname'; $port = 21; ?> PHP: I think it has been changed to : <?php $ftp_user_name = 'the ftp username'; $ftp_user_pass 'the ftp password'; $ftp_server='ftp host name or ip'; ?> But I am not sure where is the port number.. PHP: