Common examples
| Task | Command |
|---|---|
| Upload a file | scp report.pdf user@server:/tmp/ |
| Download a file | scp user@server:/tmp/report.pdf . |
| Download with a new name | scp user@server:/tmp/report.pdf copy.pdf |
| Upload a folder | scp -r site user@server:/tmp/ |
| Download what is in a folder | scp -r 'user@server:/tmp/site/*' dl/ |
| Another port | scp -P 2222 file user@server:/tmp/ |
| Use a specific key | scp -i ~/.ssh/id_work file user@server:/tmp/ |
| Keep times and modes | scp -p file user@server:/tmp/ |
| Limit speed, in Kbit/s | scp -l 800 file user@server:/tmp/ |
| Compress | scp -C file user@server:/tmp/ |
| Through a jump host | scp -J user@jump file user@server:/tmp/ |
A Host entry in ~/.ssh/config also works here: scp file server:/tmp/. See the SSH config file.
The -J row goes through a jump host. To save that route for good, see ProxyJump and jump hosts.
Copying a folder twice nests it
If the destination folder already exists, scp -r puts the folder inside it. With /tmp/site already on the server, this gave us /tmp/site/site:
scp -r site user@server:/tmp/site
So a first run creates /tmp/site, and a second creates /tmp/site/site. To copy a folder repeatedly, use rsync instead.
Names with spaces
scp "my file.txt" "user@server:/tmp/my file.txt"
This works with the default SFTP protocol. With the old protocol from -O, the same line failed with scp: ambiguous target, because the remote side reads the name again. In that case, add a second pair of quotes:
scp -O "my file.txt" 'user@server:"/tmp/my file.txt"'
Between two servers
scp -3 user@one:/tmp/file user@two:/tmp/
-3 sends the data through your machine, so neither server needs a login on the other. Since OpenSSH 8.7 this is the default, so the flag only makes it explicit. In our test, a copy without -3 also ran through the local client.
To have the first server connect directly to the second, use -R:
scp -R user@one:/tmp/file user@two:/tmp/
The first server then has to log in to the second without a prompt, and it must already know its host key. Otherwise you get Host key verification failed., which is what happened in our test.
-O: the legacy protocol
Since OpenSSH 9.0, scp uses the SFTP protocol by default. You can see this with scp -v, which prints Sending subsystem: sftp. With -O it prints Sending command: scp -v -t /tmp/.
scp -O file user@server:/tmp/
You need -O when the other side has no SFTP subsystem, such as some embedded devices. In that case, the usual error is subsystem request failed on channel 0. See that error's guide.
What scp does not do
- It does not continue a broken transfer. Run it again and it starts over.
- It does not send only what changed.
For those, use rsync, or reget in sftp. For a full comparison, read scp vs SFTP vs rsync.
Questions
How do I copy a folder with scp?
Add -r: scp -r folder user@server:/tmp/. If the destination folder already exists, scp puts the folder inside it.
How do I use scp with a different port?
Use a capital -P, as in scp -P 2222 file user@server:/tmp/. A lowercase -p keeps file times and modes instead.
Can scp resume an interrupted transfer?
No. Running it again starts the file over. Use rsync with --partial, or reget and reput inside sftp.