Transfer Files to Remote Servers using SCP

SCP (Secure Copy) is a Linux/Unix utility for copying files between systems. It can be used to copy local files to a remote system, copy remote files to your local system, or even to copy files between 2 remote systems from your local system.

Usage of SCP is quite straightforward, and copying a single local file to a remote is as simple as running the following:

scp ~/Desktop/image.jpg user@100.100.10.10:/tmp/

The command above would copy an image from your desktop to a remote server with IP address 100.100.10.10, using the account “user”, to the tmp directory. This command assumes that you have access to the remote system under the specified user account.

In the same manner, a whole directory can be copied from your local system to a remote by using the -r flag:

scp -r /User/person/assets root@remote.com:/home/website/assets/

Reversing the SCP command structure works too, so copying remote files to your local is also very simple:

scp user@remote:/test.zip ./

And by combining these ideas you can then copy files from one remote to another, from your local machine:

scp user@remote1:/payload.tar.gz user@remote2:/tmp

SCP is a powerful command that can be used adhoc or even in deployment scripts for pushing websites live, for instance.