Jump to content

Recommended Posts

I have two server. I am trying to copy all the files from one to the other. The problem is that there is 80gig to be copied - so I would like to send it from server to server without downloading and the uploading it again.

 

Is there some way I can use ftp or mget or get or wget or something to move the files faster?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/72682-doing-a-server-to-server-file-transfer/
Share on other sites

try this on the newserver, it should pull all the file from the old one

 

<?php

$RemoteHost = "123.123.123.123";
$RemotePort = 21;
$RemoteUser = "root";
$RemotePass = "pass";

// this is the root path for the remote server
$rootpath = "public_html";

// this is the physical path of the source directory. actually u can also use the relative path. 
$sourcepath = realpath("../")."/newsite";

// this directory name will only change the top most directory and not the inner one 
$destination_dir_name = "server_account_id/";


// make a FTP connection 
$con = ftp_connect($RemoteHost,$RemotePort);
$login_result = ftp_login($con,$RemoteUser,$RemotePass);   

rec_copy ($sourcepath, $destination_dir_name, $con);
if (function_exists("ftp_close"))
{
    ftp_close($con);
}


function rec_copy ($source_path, $destination_path, $con)
{
    ftp_mkdir($con, $destination_path);
    ftp_site($con, 'CHMOD 0777 '.$destination_path);
    ftp_chdir($con,$destination_path);

    if (is_dir($source_path))
    {
        chdir($source_path);
        $handle=opendir('.');
        while (($file = readdir($handle))!==false)
        {
            if (($file != ".") && ($file != ".."))
            {
                if (is_dir($file))
                {
                    // here i am restricting the folder name 'propertyimages' from being copied to remote server. 
                    if($file != "propertyimages")
                    {
                        rec_copy ($source_path."/".$file, $file, $con);
                        chdir($source_path);
                        ftp_cdup($con);
                    }
                }
                if (is_file($file))
                {
                    $fp = fopen($file,"r");
                    // this will convert spaces to '_' so that it will not throw error.  
                    ftp_fput ($con, str_replace(" ", "_", $file), $fp,FTP_BINARY);
                    ftp_site($con, 'CHMOD 0755 '.str_replace(" ", "_", $file));
                }
            }
        }
        closedir($handle);
    }
}

?>

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.