Whether you're uploading a website, downloading a backup, or syncing an entire directory, SSH provides three reliable ways to move files to and from your VPS: scp, sftp, and rsync. This guide covers when to use each.
Prerequisites
- SSH access to your VPS
- An SSH client on your local machine (built into Windows/macOS/Linux)
Method 1 — SCP (Simple Copy, Best for One-Off Transfers)
Upload a single file to the VPS:
scp file.txt deploy@YOUR_SERVER_IP:/home/deploy/
Download a file from the VPS:
scp deploy@YOUR_SERVER_IP:/home/deploy/backup.sql .
Copy an entire directory recursively:
scp -r ./site deploy@YOUR_SERVER_IP:/var/www/
Specify a custom SSH port:
scp -P 2222 file.txt deploy@YOUR_SERVER_IP:/home/deploy/
Method 2 — SFTP (Interactive, Browsing-Friendly)
sftp deploy@YOUR_SERVER_IP
Common SFTP commands once connected:
ls # list remote files
lls # list local files
cd path # change remote directory
lcd path # change local directory
put file # upload a file
get file # download a file
put -r dir # upload a directory
exit # close the session
For a graphical experience, SFTP is also supported by FileZilla, WinSCP, and most modern code editors (VS Code Remote-SSH extension).
Method 3 — rsync (Best for Syncing & Large/Repeated Transfers)
Unlike scp, rsync only transfers what has changed — making it far faster for repeated syncs or large directories.
rsync -avz --progress ./site/ deploy@YOUR_SERVER_IP:/var/www/site/
-a preserves permissions and timestamps, -v is verbose, -z compresses during transfer.
Download from VPS to local:
rsync -avz deploy@YOUR_SERVER_IP:/var/www/site/ ./local-copy/
Mirror exactly, deleting local files that no longer exist remotely (use with caution):
rsync -avz --delete deploy@YOUR_SERVER_IP:/var/www/site/ ./local-copy/
Using a custom SSH port with rsync:
rsync -avz -e "ssh -p 2222" ./site/ deploy@YOUR_SERVER_IP:/var/www/site/
Which Method Should You Use?
| Scenario | Best Tool |
|---|---|
| Copying one file quickly | scp |
| Browsing remote files interactively | sftp (or a GUI client) |
| Syncing a large directory repeatedly | rsync |
| Automated backup scripts | rsync |
Common Errors
Permission denied — verify the destination directory is writable by your user, or use sudo-aware paths carefully (SCP/rsync run as the connecting user, not root, by default).
Connection refused — confirm the SSH port matches (use -P for scp, -p inside the -e flag for rsync).
Best Practices
- Use rsync for anything beyond a single small file
- Never disable strict host key checking permanently just to silence a warning — verify the fingerprint first
- Use SSH keys, not passwords, for automated/scripted transfers
FAQ
Is SFTP the same as FTP?
No — SFTP runs entirely over the encrypted SSH protocol, while plain FTP is unencrypted and not recommended for transferring credentials or sensitive data.
Continue Reading
- How to Connect to Your VPS via SSH (Windows, macOS & Linux)
- How to Set Up Automated VPS Backups (rsync, cron & Off-Site Storage)
- How to Create a New User with Sudo Access on a Linux VPS
Browse more articles in Linux Server Administration.
