scp

What is scp?

SCP (secure copy) is a command-line utility that allows you to securely copy files and directories between two locations.

With scp, you can copy a file or directory:

  • From your local system to a remote system.

  • From a remote system to your local system.

  • Between two remote systems from your local system.

When transferring data with scp, both the files and password are encrypted so that anyone snooping on the traffic doesn’t get anything sensitive.

Note

The scp command relies on ssh for data transfer, so it requires an ssh key or password to authenticate on the remote systems.

How to use scp

# syntax local copy to remote
scp <OPTIONS> <LOCALFILE> <REMOTEUSER@HOST:/PATH/TO/FILEORDIRECTORY>

# syntax remote to local
scp <OPTIONS> <USER@HOST:/PATH/TO/FILEORDIRECTORY> <LOCALFILE>

##### examples without parameters
scp michel@172.16.15.129:/tmp/test.txt ./test.txt # copy to local directory
scp michel@172.16.15.129:/tmp/test.txt /Users/michel/Desktop/test.txt # copy to directory /Users/michel/Desktop/

scp ./test.txt michel@172.16.15.129:/tmp/test.txt # copy to remote directory
scp /Users/michel/Desktop/test.txt michel@172.16.15.129:/tmp/test.txt # copy to remote directory 

##### examples with parameters
scp -P <PORT> file.txt <REMOTEUSER@HOST:/PATH/TO/FILEORDIRECTORY> # the -P specifies the port if it differs from port 22
scp -P <PORT> <REMOTEUSER@HOST:/PATH/TO/FILEORDIRECTORY> file.txt # the -P specifies the port if it differs from port 22

scp -r <LOCALDIRECTORY> <REMOTEUSER@HOST:/PATH/TO/FILEORDIRECTORY> # the -r copies a directory recursive
scp -r <REMOTEUSER@HOST:/PATH/TO/FILEORDIRECTORY> <LOCALDIRECTORY> # the -r copies a directory recursive

Example

MacBook-Pro-van-Michel:~ michel$ scp -r michel@172.16.15.129:/test /Users/michel/Desktop/
michel@172.16.15.129's password: 
test2.txt                                     100%    0     0.0KB/s   00:00    
test2.txt                                     100%    0     0.0KB/s   00:00    
test1.txt                                     100%    0     0.0KB/s   00:00    

Last updated