Secure Copy (SCP) is a useful UNIX command that allows you to securely copy files and directories between your local machine and a remote computer.
In the examples below “-P 22” is not actually needed if the SSH port is 22. Many of the servers I connect to have a different port for security reasons so I’ve included it.
While I wouldn’t recommend this as a port for SSH it works as a good example, if you have port 1234 for SSH your command would change from “-P 22” to “-P 1234”
Make sure the P is a capital P
If you need more explanation or information about SCP you can do this command in terminal
man scp
First to upload a file you need a command like below, an understanding of each file system is helpful.
In the example below we connect to the remote computer 192.168.1.40 with username “testuser” on port 22 to send “SomeFile.txt” in our home directory to the files directory in the home folder of “testuser” on the remote computer.
NOTE: if you have a hostname/domain you can use that instead of the IP
scp -P 22 ~/SomeFile.txt testuser@192.168.1.40:~/files
Now if you reverse the command you can download.
In the example below we connect to the remote computer 192.168.1.40 with the username “testuser” on port 22 to get “SomeFile.txt” in the files directory in the home folder of “testuser” on the remote computer and download it to our home directory
scp -P 22 testuser@192.168.1.40:~/files/SomeFile.txt ~/
Now as before we can also download/upload entire directories as well.
In this example we must include “-r” to define recursive or all files in directory
scp -r -P 22 testuser@192.168.1.40:~/files/ ~/
scp -r -P 22 ~/ testuser@192.168.1.40:~/files/
If you have a server that you connect to that doesn’t use a password but uses a shared key you simply need to add that to the command.
scp -r -P 22 -i ~/Documents/SomeKey.key testuser@192.168.1.40:~/files/ ~/