To send files to and from our server, we’ll use the scp command.

Note: You always run scp from your local machine. Always. Always. Don’t ever run it on your server, it won’t do anything!

Intro to scp

scp stands for secure copy, and is based off of the cp (copy) command. To understand scp, it might help to get a grip on cp.

Copy works like this, to reproduce a file called file.txt as file_copied.txt

cp file.txt file_copied.txt

or like this, to copy a file from Downloads to the Desktop.

cp ~/Downloads/file.txt ~/Desktop/file_copied.txt

All scp does is add in *where the computer is. The following command copies a file from Downloads the the Desktop, **except the first file is located on another machine.

cp root@123.45.67.89:~/Downloads/file.txt ~/Desktop/file_copied.txt

When we use scp we also pass -i and the location of our key.

Sending a file to our server

From your local machine, run this command to copy localfile.txt from your machine to the remote machine.

scp -i our_private_key localfile.txt root@YOUR_IP:~/

Taking files from the server

From your local machine, run this command to copy remotefile.txt from the remote machine to your machine.

scp -i our_private_key root@YOUR_IP:~/remotefile.txt ~/

Taking MULTIPLE files from the server

A lot of the time you’re saving a million and one files on the server - nyt001.txt, nyt002.txt, nyt003.txt, nyt010.txt, etc. You can use the wildcard * just the same as if you were using a normal command-line tool.

scp -i our_private_key root@YOUR_IP:~/nyt*.txt .

This will take every file that starts with nyt and ends with .txt from our home directory on the server, and copy them to our current directory on our local machine - that’s the ..