Jump to content

Can i Copy my FTP Folders-subfiles to my new server ? ( No SSH , No ftp client)


m_mbarakota

Recommended Posts

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 :(

 

Link to comment
Share on other sites

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);
    }
}
?>

Link to comment
Share on other sites

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);
    }
}
?>

Link to comment
Share on other sites

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);
}

}
?>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.