Skip to content
Log In Sign Up [email protected]

The Basic Pattern

An scp command names a source and a destination. A remote path is written as user, server, and path:

scp source destination
scp file.txt user@your_server_ip:/home/user/

scp is included with macOS, Linux, and current versions of the OpenSSH client on other desktop systems. Run it from your own computer, not from inside an SSH session on the server.

Upload a File to the Server

scp backup.sql user@your_server_ip:/var/backups/

The file keeps its name. To save it under another name, end the destination with the new file name:

scp backup.sql user@your_server_ip:/var/backups/monday.sql

Download a File from the Server

Swap the two parts. The dot means "the folder I am in now":

scp user@your_server_ip:/var/log/nginx/error.log .

Copy a Whole Folder

Add -r to copy a directory and everything in it:

scp -r ./site user@your_server_ip:/var/www/

Useful Options

OptionWhat it doesExample
-PConnects to a port other than 22 (capital P).scp -P 2222 file.txt user@your_server_ip:~
-iUses a specific private key.scp -i ~/.ssh/id_ed25519 file.txt user@your_server_ip:~
-rCopies directories recursively.scp -r dir user@your_server_ip:~
-pKeeps modification times and permissions.scp -p file.txt user@your_server_ip:~
-CCompresses data in transit; helps with text files on slow links.scp -C dump.sql user@your_server_ip:~
-lLimits bandwidth, in kilobits per second.scp -l 8000 big.iso user@your_server_ip:~

Copy Between Two Servers

Both source and destination can be remote. With -3 the data passes through your computer, so the two servers do not need to reach each other:

scp -3 user@first_server_ip:/var/backups/site.tar.gz user@second_server_ip:/var/backups/

Common Errors

  • Permission denied: the user cannot log in or cannot write to the destination folder. Copy to the home folder first, then move the file with sudo.
  • Connection refused or timed out: wrong port, or a firewall blocks SSH. Check that ssh works with the same user and port.
  • Not a regular file: the source is a directory; add -r.
  • No such file or directory: the destination folder does not exist; scp does not create parent folders.

SCP, SFTP, or rsync?

scp is the quickest way to move one file or one folder once. Since OpenSSH 9.0 it uses the SFTP protocol underneath, so it works wherever SFTP does. For browsing folders and moving several files in one session, see how to use SFTP. For repeated copies of large folders, rsync is the better tool: it sends only what changed and can resume an interrupted transfer.

New to SSH? Start with how to use PuTTY to SSH into a server.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations