SCP (secure copy) is a command which allows you to transfer files from one machine to another using SSH and is an extremely useful tool. Unfortunately the documentation can be a little confusing; the syntax for this command is:
scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] -S program] [[user@]host1:]file1 [...] [[user@]host2:]file2
And so I’ve documented some uses of the command here for future reference, which I will update as necessary.
Using the -P option allows you to specify which port to use; usually this isn’t necessary as it will use port 22 as default (the same as SSH). To set the port to 222 you would use:
scp -P 222 ...
Copy file from local machine to remote machine
One of the most common uses of the scp command is to transfer a file from the current (local) machine to a remote machine such as a server or another computer on your network; the following command will do this:
scp /path/to/local/file user@remotemachine:/path/to/remote/location
Copy file from remote machine to local machine
Another common use for the command is to transfer a file from a remote location (such as a server you have SSH access to) to your local machine; which can be done by using the following command:
scp user@remotemachine:/path/to/remote/file /path/to/local/location