Applies to: OpenSSH scp on Linux, macOS and Windows 10 and 11
scp copies files between computers over SSH. To copy a whole folder with its subfolders, add -r (recursive). We tested every example below between a Mac and a Ucartz VPS running AlmaLinux 9.
Upload a folder to a server
scp -r site user@server.example.com:/var/www/
This creates /var/www/site on the server, with all files and subfolders (hidden files included).
Download a folder from a server
scp -r user@server.example.com:/var/www/site ./site-backup
Where does the folder end up?
- If the destination folder already exists, the copied folder goes inside it:
scp -r site server:/tmp/destgives/tmp/dest/site. - If it doesn’t exist, it is created with the new name: the contents of
siteend up directly in/tmp/dest. - To copy only the contents into an existing folder, use
site/*(this skips hidden files at the top level):scp -r site/* server:/tmp/dest/
Useful options
scp -r -P 2222 site user@server:/var/www/ # SSH on another port (capital P) scp -rp site user@server:/var/www/ # keep modification times and permissions scp -r -i ~/.ssh/id_ed25519 site user@server:/var/www/ # use a specific key scp -r -C site user@server:/var/www/ # compress while copying
Faster and resumable: rsync
scp -r copies everything every time. For large folders or repeated copies, rsync sends only what changed and can resume after a break:
rsync -avz --progress site/ user@server.example.com:/var/www/site/
More: rsync command examples.
Good to know
- Since OpenSSH 9.0,
scpuses the SFTP protocol underneath. If a very old server fails, add-Oto use the legacy protocol. - “Permission denied” usually means you can’t write to the destination folder; copy to your home folder first.
- Windows 10 and 11 include
scpin PowerShell; WinSCP and FileZilla are graphical alternatives.
To leave some files out, see how to exclude files when copying with scp. For interactive uploads, see the put command in sftp.
Ucartz services for this topic
- KVM VPS hosting: NVMe SSD and full root access, with Free Basic Managed Support.
- Unmanaged dedicated servers: full root access and free IPMI KVM, with Free Basic Managed Support.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
