m_mbarakota Posted January 24, 2009 Share Posted January 24, 2009 Please help !! i had a ftp account i store about 50G.B. files on it i uploaded them in too long time but it is going to expire and i buy a new ftp account to transfer all my data on it. i try to use flashfxp and WS_FTP Professional it takes TOO LONG TIME to transfer the first folder only, while there is another 552 folder i am asking is there is anyway to transfer Folders "not only files" remotely i had a script to do this for files, but it doesn't work with folders. i tried net2ftp and other script like that, BUT my old ftp is little slow, so when i transfer a big folders or files it takes too long while the script finish loading and my browser always crash, is there is anyway to make the script work automatic without leave the browser open? i tried Server to Server Transfer script it works with files only, but i can't transfer folders Another problem my old ftp don't have ssh or sftp also dunn have PHP but my new website include PHP and FTP but no also ssh Can anyone help me doing that, as my account is going to expire and i can't copy my data i am afraid to lose it, it takes from me many years to get all data Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/ Share on other sites More sharing options...
MadTechie Posted January 25, 2009 Share Posted January 25, 2009 Are you trying to use FTP from you PC that connects to both server and transfers the data ? if so thats going to take ages! you best bet is to create a php script thats download the files to the host machine.. then put that script on the new server and let it run.. does the script below give you a list of files on the old server ?when its ran from the new server ? update this line first $dir = "ftp://usernae:password@remotehost.com/myfiles/"; <?php $dir = "ftp://usernae:password@remotehost.com/myfiles/"; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { echo "filename: $file : filetype: " . filetype($dir . $file) . "<br>\n"; } closedir($dh); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-745642 Share on other sites More sharing options...
m_mbarakota Posted January 25, 2009 Author Share Posted January 25, 2009 Yes it works, it gives me a list of all sub-directories in the folder i added. i don't know a script that download FOLDERS to the new host all scripts i found is to download files, and when i use net2ftp to copy the folders to another FTP account. it takes too long time to copy them too i wish to find script i run it once, and it continue copying even if i close the browser Are you trying to use FTP from you PC that connects to both server and transfers the data ? if so thats going to take ages! you best bet is to create a php script thats download the files to the host machine.. then put that script on the new server and let it run.. does the script below give you a list of files on the old server ?when its ran from the new server ? update this line first $dir = "ftp://usernae:password@remotehost.com/myfiles/"; <?php $dir = "ftp://usernae:password@remotehost.com/myfiles/"; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { echo "filename: $file : filetype: " . filetype($dir . $file) . "<br>\n"; } closedir($dh); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-745657 Share on other sites More sharing options...
MadTechie Posted January 25, 2009 Share Posted January 25, 2009 If you want to run it outside the browser your need to use ssh or a crownjob Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-745675 Share on other sites More sharing options...
m_mbarakota Posted January 25, 2009 Author Share Posted January 25, 2009 i dunn have ssh on this ftp server. and as iam a beginner i dunno wht is "crownjob" can you tell me what required for crownjob? and where i can find a php script to copy "folders-subfolders and all included files" not file by file? Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-745677 Share on other sites More sharing options...
MadTechie Posted January 25, 2009 Share Posted January 25, 2009 Wouldn't be hard to write, but the browser window will be open during the hold process, (which will be awhile) Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-745682 Share on other sites More sharing options...
m_mbarakota Posted January 25, 2009 Author Share Posted January 25, 2009 so can you help me write such code please ? Wouldn't be hard to write, but the browser window will be open during the hold process, (which will be awhile) Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-746096 Share on other sites More sharing options...
m_mbarakota Posted January 26, 2009 Author Share Posted January 26, 2009 i found cron job manager in my Cpanel of the new server but the old one don't have Cpanel can i use cron job from my new server to copy all folders in my old ftp and which script and Command to run? Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-746146 Share on other sites More sharing options...
MadTechie Posted January 26, 2009 Share Posted January 26, 2009 Okay this is very untested.. as not tested at all.. <?php //EG $FTP = new FTPUpload(); $FTP->UploadFolder("Old_html/","New_html/"); class FTPUpload { protected $conn_id; private $FTP_HOST ="ftp.NewServer.com"; private $FTP_USER ="NewServerUser"; private $FTP_PW ="NewServerPass"; private $FTP_ROOT_DIR="/"; private $FTP_DIR = "public_html/"; private $LOCAL_SERVER_DIR = "public_html/"; private $mode = FTP_BINARY; // or FTP_ASCII function __construct() { $this->conn_id = ftp_connect($this->FTP_HOST); } function UploadFolder($FromFolder, $ToFolder) { $this->LOCAL_SERVER_DIR = $FromFolder; $this->FTP_DIR = $ToFolder; if(ftp_login($this->conn_id, $this->FTP_USER, $this->FTP_PW)) { $this->GetFiles($FromFolder); ftp_quit($this->conn_id); } } //Connect to New Server function UploadFile($f) { ftp_pwd($this->conn_id); ftp_mkdir($this->conn_id,$this->FTP_DIR); ftp_chdir($this->conn_id,$this->FTP_DIR); $from = fopen($this->LOCAL_SERVER_DIR.$files,"r"); foreach($f as $files) { $from = fopen($this->LOCAL_SERVER_DIR.$files,"r"); if(ftp_fput($this->conn_id, $files, $from, $this->mode)) { print $files."<br>"; } } if(ftp_fput($this->conn_id, $files, $from, $this->mode)) { print "Uploaded: $files<br>"; } } function GetFiles($dir) { if(!$dh = @opendir($dir)) return; while (false !== ($obj = readdir($dh))) { if($obj=='.' || $obj=='..') continue; if(is_dir($obj)) { $this->GetFiles($dir.'/'.$obj); }else{ $f[]="$file"; } } $this->UploadFile($f); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-746179 Share on other sites More sharing options...
m_mbarakota Posted January 26, 2009 Author Share Posted January 26, 2009 when i try to use this code it give me the following : Warning: ftp_fput() [function.ftp-fput]: No file name in /home/mysite.com/public_html/uploading.php on line 51 Warning: Invalid argument supplied for foreach() in /home/mysite.com/public_html/uploading.php on line 42 Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-746242 Share on other sites More sharing options...
m_mbarakota Posted January 26, 2009 Author Share Posted January 26, 2009 i try to use this code but it give me error Fatal error: Call to undefined function dircopy() in /home/username/public_html/copytest.php on line 60 can any one help? <?php $srcdir = 'ftp://my.site.com/public_html/files/'; $dstdir ='/home/username/public_html/upload/'; function dir_copy($srcdir, $dstdir, $offset = '', $verbose = false) { if(!isset($offset)) $offset=0; $num = 0; $fail = 0; $sizetotal = 0; $fifail = ''; if(!is_dir($dstdir)) mkdir($dstdir); if($curdir = opendir($srcdir)) { while($file = readdir($curdir)) { if($file != '.' && $file != '..') { // $srcfile = $srcdir . '\\' . $file; // $dstfile = $dstdir . '\\' . $file; $srcfile = $srcdir . '/' . $file; $dstfile = $dstdir . '/' . $file; if(is_file($srcfile)) { if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1; if($ow > 0) { if($verbose) echo "Copying '$srcfile' to '$dstfile'...<br />"; if(copy($srcfile, $dstfile)) { touch($dstfile, filemtime($srcfile)); $num++; chmod($dstfile, 0777); $sizetotal = ($sizetotal + filesize($dstfile)); if($verbose) echo "OK\n"; } else { echo "Error: File '$srcfile' could not be copied!<br />\n"; $fail++; $fifail = $fifail.$srcfile.'|'; } } } else if(is_dir($srcfile)) { $res = explode(',',$ret); $ret = dircopy($srcfile, $dstfile, $verbose); $mod = explode(',',$ret); $imp = array($res[0] + $mod[0],$mod[1] + $res[1],$mod[2] + $res[2],$mod[3].$res[3]); $ret = implode(',',$imp); } } } closedir($curdir); } $red = explode(',',$ret); $ret = ($num + $red[0]).','.(($fail-$offset) + $red[1]).','.($sizetotal + $red[2]).','.$fifail.$red[3]; return $ret; } //run function dir_copy($srcdir, $dstdir, $offset = '', $verbose = false); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-746289 Share on other sites More sharing options...
Philip Posted January 26, 2009 Share Posted January 26, 2009 As the error states: Call to undefined function dircopy... you're missing the underscore, '_'. However, looking through the code, and seeing there is no line 60 in the one you provided.... is there somewhere else where you tried to call the function? Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-746291 Share on other sites More sharing options...
m_mbarakota Posted January 26, 2009 Author Share Posted January 26, 2009 i found where is the mistake but with this new code, i test it with two ftps servers it works well but when i try to use it with my ftp (which have port 47624) it doesn't work and didn't copy any file or folder giving error Warning: opendir(ftp://...@xxx.myftp.info:47624/downloads/) [function.opendir]: failed to open dir: Operation now in progress in /home/username/public_html/copytest.php on line 34 Warning: opendir() [function.opendir]: connect() failed: Connection timed out in /home/username/public_html/copytest.php on line 34 but it works well with all other ftp with normal port i use it with many ftp and it works anyone has any idea why?? here is the code i use <?php $srcdir = 'ftp://xxxxxxx.myftp.info:47624/downloads/'; $dstdir ='/home/username/public_html/a/'; function dir_copy($srcdir, $dstdir, $offset = '', $verbose = false) if(!isset($offset)) $offset=0; $num = 0; $fail = 0; $sizetotal = 0; $fifail = ''; if(!is_dir($dstdir)) mkdir($dstdir); if($curdir = opendir($srcdir)) { while($file = readdir($curdir)) { if($file != '.' && $file != '..') { $srcfile = $srcdir . '/' . $file; $dstfile = $dstdir . '/' . $file; if(is_file($srcfile)) { if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1; if($ow > 0) { if($verbose) echo "Copying '$srcfile' to '$dstfile'...<br />"; if(copy($srcfile, $dstfile)) { touch($dstfile, filemtime($srcfile)); $num++; chmod($dstfile, 0777); $sizetotal = ($sizetotal + filesize($dstfile)); if($verbose) echo "OK\n"; } else { echo "Error: File '$srcfile' could not be copied!<br />\n"; $fail++; $fifail = $fifail.$srcfile.'|'; } } } else if(is_dir($srcfile)) { $res = explode(',',$ret); $ret = dir_copy($srcfile, $dstfile, $verbose); $mod = explode(',',$ret); $imp = array($res[0] + $mod[0],$mod[1] + $res[1],$mod[2] + $res[2],$mod[3].$res[3]); $ret = implode(',',$imp); } } } closedir($curdir); } $red = explode(',',$ret); $ret = ($num + $red[0]).','.(($fail-$offset) + $red[1]).','.($sizetotal + $red[2]).','.$fifail.$red[3]; return $ret; } //run function dir_copy($srcdir, $dstdir, $offset = '', $verbose = false); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142302-can-i-copy-my-ftp-folders-subfiles-to-my-new-server-no-ssh-no-ftp-client/#findComment-746335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.