Need to upload a backup or download a log? scp and sftp transfer files over SSH, so they work wherever you can log in, with no FTP server to install and everything encrypted. They are built into Linux, macOS and Windows 10/11.
Before you start
- SSH access to the server (password or key).
- The SSH port if it is not 22.
Copy files with scp
The syntax is scp source destination, where a remote path is written user@host:path.
Upload a file:
scp backup.tar.gz root@203.0.113.10:/root/Download a file:
scp root@203.0.113.10:/var/log/nginx/error.log .Copy a whole folder with -r:
scp -r ./site root@203.0.113.10:/var/www/| Option | Does |
|---|---|
-P 2222 | Custom SSH port (capital P for scp) |
-i ~/.ssh/key | Use a specific private key |
-C | Compress during transfer |
-p | Preserve modification times and modes |
-l 8000 | Limit bandwidth (Kbit/s) |
If you have a Host alias in ~/.ssh/config, use it directly: scp file myvps:/root/.
Work interactively with sftp
sftp -P 22 root@203.0.113.10(For sftp the port option is also -P.) You get an sftp> prompt with familiar commands:
| Command | Does |
|---|---|
ls / lls | List remote / local files |
cd / lcd | Change remote / local directory |
put file | Upload |
get file | Download |
put -r folder / get -r folder | Recursive transfer |
reput / reget | Resume an interrupted transfer |
mkdir, rm, rename | Manage remote files |
bye | Exit |
Use a graphical client
If you prefer drag and drop, FileZilla, WinSCP (Windows) and Cyberduck (macOS) all speak SFTP. Choose protocol SFTP, port 22 (or yours), and your SSH user. They can use your SSH private key too (FileZilla and WinSCP may ask to convert it to PuTTY's .ppk format).
Which tool to use
- scp: quick one-off copies from the command line.
- sftp: browsing, several files, resuming large transfers.
- rsync: repeated syncs or very large folders, since it transfers only changes.
Troubleshooting
- Permission denied on upload: your user cannot write the target folder. Upload to your home directory, then move it with sudo.
- Connection refused or timed out: same causes as SSH (wrong port, firewall, blocked IP). Check SSH login first.
- scp: Received message too long: a startup file like
.bashrcprints text for non-interactive shells. Wrap echo lines in a check for an interactive shell. - Files with spaces: quote the remote path:
scp "root@ip:/root/my file.txt" .
scp and sftp FAQ
Is scp deprecated?
The old scp protocol is being phased out, but the scp command remains: recent OpenSSH versions use the SFTP protocol underneath, so it keeps working.
Is SFTP the same as FTPS?
No. SFTP runs over SSH on port 22; FTPS is FTP with TLS on ports 21/990. Both are encrypted.
Can I use SFTP with cPanel hosting?
Yes, if SSH access is enabled for your account: use your cPanel username and the SSH port your host provides.
