jump to navigation

Copy/Transfer Files Between Two Servers Using Linux scp December 26, 2010

Posted by Tournas Dimitrios in Linux.

The other day we ran into a good problem that our site has grown and we are in need of a new server. So we ordered the server and now we need to transfer all the files from the old server to the new one. But rather than downloading all the files to our local machines then re-cuploading them to the new server, we’re going to show you how you can skip the middle man and transfer files from server to server.

The only requirements is that you need to have SSH access to both servers. The Linux command scp which stands for secure copy is the utility for our needs.

Using  scp with the following options:

  • r = recursively copy entire directories
  • C = compression enable
  • p = preserves modification times, access times, and modes from the original file

// To transfer all the files in the httpdocs directory to a folder on the remote machine
scp -rpC /var/www/httpdocs/*  remote_user@remote_domain.com:/var/www/httpdocs

// Transfer only PHP files
scp -rpC /var/www/httpdocs/*.php remote_user@remote_domain.com:/var/www/httpdocs

Also, if you’re going to transfer a lot of data between the webservers, you probably want to add the nohup command too. nohup runs a command even if the session is disconnected or the user logs out. Another bit you can add is trailing ampersand (&) to the end the command to launch it in the background and get your command prompt back right away.

nohup scp -rpC /var/www/httpdocs/* remote_user@remote_domain.com:/var/www/httpdocs &

Hope this helps someone as much as it did me today.



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s