SCP | cli | Linux
Server to client
scp -P port user@server:/path/to/remote/file ./
Client to server
scp -P port /path/to/some/file user@machine:/path/to/location
Path: you must have the write or read rights.
Copy one single local file to a remote destination
scp /path/to/source-file user@host:/path/to/destination-folder/
So, if you wan to copy the file /home/user/table.csv to a remote host named host.example.com and copy there to jane's home folder, use this command.
scp /home/user/table.csv email@example.com:/home/jane/
Copy one single file from a remote server to your current local server
scp user@host:/path/to/source-file /path/to/destination-folder
Let's say now you want to copy the same file from jane's home folder in host.example.com to your local home folder.
scp firstname.lastname@example.org:/home/jane/table.csv /home/user/
Copy one single file from a remote server to another remote server
With scp you can copy files between remote servers from a third server without the need to ssh into any of them, all weight lifting will be done by scp itself.
scp user1@server1:/path/to/file user2@server2:/path/to/folder/
Let's say now you want to copy the same table file from jane's home folder to pete's home folder in another remote machine.
scp email@example.com:/home/jane/table.csv firstname.lastname@example.org:/home/pete/
Copy one single file from a remote host to the same remote host in another location
scp email@example.com:/home/jane/table.csv firstname.lastname@example.org:/home/pete/
This time, you will be copying from one host to the same host, but on different folders under the control of different users.
Copy multiple files with one command
You can copy multiple files at once without having to copy all the files in a folder, or copy multiple files from different folders putting them in a space separated list.
scp file1.txt file2.txt file3.txt email@example.com:/home/pete/
If the files are in different folders, just specify the complete path.
scp /path/to/file1.txt /path/to/file2.txt /path/to/file3.txt firstname.lastname@example.org:/home/pete/
Copy all files of a specific type
scp /path/to/folder/*.ext user@server:/path/to/folder/
This will copy all files of a given extension to the remote server. For instance, you want to copy all your text files (txt extension) to a new folder.
scp /home/user/*.txt email@example.com:/home/jane/
You can make use of wildcards in any way you want.
Copy all files in a folder to a remote server
scp /path/to/folder/* user@server:/path/to/folder/
This will copy all files inside local folder to the remote folder, let's see an example.
scp /home/user/html/* firstname.lastname@example.org:/home/jane/backup/
All files in local folder html, will be copied to backup folder in host.example.com
Copy all files in a folder recursively to a remote server
scp -r /home/user/html/* email@example.com:/home/jane/backup/
Same as the previous example, but this time it will copy all contentes recursively
Copy a folder and all its contents to a remote server
scp -r /path/to/source-folder user@server:/path/to/destination-folder/
This time the folder itself is copied with all its contents and not only the contents. One more time we'll use an example.
scp -r /home/user/html firstname.lastname@example.org:/home/jane/backup/
This will result in having in the remote server this: /home/jane/backup/html/.... The whole html folder and its contentes recursively have been copied to the remote server.
We have seen the basic uses scp, now we will see some special uses and tricks of this great command
scp uses AES-128 to encrypt data, this is very secure, but also a litle bit slow. If you need more speed and still have security, you can use Blowfish or RC4.
To increase scp speed change chipher from the default AES-128 to Blowfish
scp -c blowfish user@server:/home/user/file .
Or use RC4 which seems to be the fastest
scp -c arcfour user@server:/home/user/file .
This last one is not very secure, and it may not be used if security is really an issue for you.
If security is what you want, you can increase it, you will lose some speed though.
scp -c 3des user@server:/home/user/file .
You may limit the bandwidth used by scp command
scp -l limit username@server:/home/uername/* .
Where limit is specified in Kbit/s. So for example, if you want to limit speed at 50 Kbps
scp -l50 user@server:/path/to/file /path/to/folder
Yoy can save bandwidth by enabling compression, let's see our example with compression.
scp -C user@server:/path/to/file /path/to/folder
Use IPv4 or IPv6
If you want to force the use of either IPv4 or IPv6 use any of these ones.
scp -4 user@server:/path/to/file /path/to/folder
The above one is for IPv4, and below for IPv6.
scp -6 user@server:/path/to/file /path/to/folder
Specify a port
If the remote server does not have ssh listening on default 22 port, you can make scp to use the port where the remote server is listening to:
scp -P [port] [user]@[server]:[path/to/]file [/path/to/]file
Using the capital letter P you can make scp to use a port other than 22 which is the default for ssh. Let's say your remote server is listening on 2222.
scp -P 2222 user@server:/home/jane/file /home/jane/
Use verbose output
If you want to see what is happening under the hood, use the -v parameter for a verbose output
scp -v user@server:/home/jane/file /home/jane/
If you are working on a Windows powered computer, you can still enjoy scp in various ways, of course if you are a "*nix guy" you will prefer the command line, and you also have GUI tools available.
pscp is a shell command that works almost on Windows Shell almost the same way that scp works on Linux or Mac OS X, you first need to download it from this page, here is the direct link.
Once downloaded you can invoque it from the Windows command line, go to the start menu and click on run then write
And press ENTER, if you are on Windows 8.x hit the Windows/Super key and click on the magnifier lens, type cmd and hit ENTER.
Once in the command line, be sure to be in the directory where the pscp file was downloaded, or add that folder to your PATH, let's suppose the folder is your Downloads folder, run this command:
You will have to set that command every time you open a new command shell, or you can add the path permanently, how to do that is out of the scope of this article.
Below are the options of the command, you will see that the options available let you do almost everything.
PuTTY Secure Copy client
Usage: pscp [options] [user@]host:source target
pscp [options] source [source...] [user@]host:target
pscp [options] -ls [user@]host:filespec
-V print version information and exit
-pgpfp print PGP key fingerprints and exit
-p preserve file attributes
-q quiet, don't show statistics
-r copy directories recursively
-v show verbose messages
-load sessname Load settings from saved session
-P port connect to specified port
-l user connect with specified username
-pw passw login with specified password
-1 -2 force use of particular SSH protocol version
-4 -6 force use of IPv4 or IPv6
-C enable compression
-i key private key file for authentication
-noagent disable use of Pageant
-agent enable use of Pageant
-batch disable all interactive prompts
-unsafe allow server-side wildcards (DANGEROUS)
-sftp force use of SFTP protocol
-scp force use of SCP protocol
Copy files from Windows to Linux
You can use scp command to copy files from Linux to Windows
pscp c:\path\to\file user@remote-server:/path/to/remote-folder
Copy files from Linux to Windows
You can also copy files from Windows to Linux, using pscp from the Windows computer you can "push" the files to the Linux, Max OS X or *BSD server.
pscp user@remote-server:/path/to/remote-file c:\path\to\local-folder\
You can specify the protocol that scp command for Windows will use at the time of connection.
This will force pscp to use scp protocol
This will force pscp to use sftp protocol, which is a newer protocol than scp protocol