Chances are you have a bunch of different hosts that are housing your website files, for the sake of data safety (never put all eggs in a single basket) and possibly some SEO advantage. If that is the case, you will infrequently come to the need to move some files from one host server to another. How does one do that?
Well the straight answers include downloading the files from the source host and then uploading it to destination one via FTP. It’s not much of a time-waster with small number of files, especially those small in size. However, if it’s an impressively large chunk of package, say, 4GB, or thousands of files, this’d be quite a daunting job that may very well take the better part of your day or even a few days.
The shortcut is to transfer those files directly from the original host to the other, via SSH. That is of course, if you have both hosts enabled with SSH.
Log into the destination host via SSH and try the following command:
scp -r remoteuser@remote.host.com:/home/remoteuser/dir-to-be-transferred /home/localuser/backup
Wherein remote.host.com is the address of the source host and remoteuser is the SSH user account that can read the remote directory to be transferred, namely /home/remoteuser/dir-to-be-transferred. The last argument is the local path that’s receiving the incoming files / directory.
You can also transfer a specific file:
scp remoteuser@remote.host.com:/home/remoteuser/mybackup.tar.gz /home/localuser/backup
As a matter of fact, scp works the exactly same way as an ordinary cp command except it’s able to copy files back and forth remote hosts. The “s” of “scp” stands for safe, because all the data transferred is encrypted on SSH.
It’s a great way to back up your valuable website data across multiple different hosts that are physically far away from each other. With the help of crontab jobs that do the regular backups automatically, this is even better than some of the commercial backup services.
The command of rsync is a more preferable option to scp for synchronizing stuff across different hosts because it works incrementally, thus saving bandwidth, especially with large backups.
Related Posts
- Dropbox review – the most intuitive online backup storage, data synchronizing and files sharing software
- Essential SSH – 19 Linux SSH Commands You Simply Cannot Live Without
- Free 2GB HTML static web pages hosting
- PHP: Change Current Working Directory
- Linux wget Command to Download and Mirror a Website in Static Local Copy

{ 2 comments… read them below or add one }
I believe you need a -r flag if you want to copy an entire directory. Otherwise it thinks its a file and gives you an error.
Thanks for the tip, just added it. :)