scp - Secure Copy
Sep 16, 2015
scp
or secure copy is a program that allows you to transfer files to/from another machine via SSH. You can think of it as the cp
command with SSH added to it. It should be available on all *nix based systems and is available on cygwin if you install it.
Copy a Local File
This command copies a local file to a remote server using scp
.
scp /your/file/name user@host:/remote/path/
Copy a Remote File
And of course, you can copy remote files to your local machine.
scp user@host:/your/file/name .
The “.” at the end will download the file to the current folder.
Keys
SSH keys can also be used by specifying the -i <path>
argument to the beginning of the command.
scp -i /path/to/key user@host:/your/file/name .
Port Changing
If SSH is running on a port other than 22
, you can specify it at the beginning just like the key file. With scp
, the port argument must be capitalized (P) and cannot be lowercase (p) like it is with ssh
.
scp -P 222 user@host:/your/file/name .
Recursive
Sometimes it can be useful to upload every file in multiple directories recursively. Simply add -r
to the command.
scp -r /your/directory/path user@host:/remote/path/