Secure File Transfer with SCP, SFTP, and rsync
Move files between machines over the encrypted SSH channel. Compare scp, sftp, and rsync, learn their key options, and choose the right tool for one-off copies, interactive transfers, and efficient syncs.
Secure File Transfer with SCP, SFTP, and rsync is a free Linux Server Deployment & SSH Mastery lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Server Deployment & SSH Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Transferring Files over SSH
You have mastered tunnels, agents, and multi-hop connections. The same SSH foundation also powers secure file transfer — no extra service or open port required.
Three tools ride on SSH: scp for quick copies, sftp for interactive sessions, and rsync for efficient synchronization.
scp: Simple Copies
scp works just like cp but across machines. The remote side uses user@host:path syntax.
This uploads a local file to the server.
scp report.pdf deploy@server:/home/deploy/docs/scp: Download and Directories
Swap the order of arguments to download. Add -r to copy whole directories recursively.
scp deploy@server:/var/log/app.log ./
scp -r deploy@server:/etc/myapp ./backup/scp with Custom Port and Keys
If your server uses a non-standard port, note that scp uses an uppercase -P (unlike ssh's lowercase -p). You can also point to a specific key with -i.
scp -P 2222 -i ~/.ssh/deploy_key file.txt deploy@server:/tmp/sftp: Interactive Transfers
sftp opens an interactive session resembling an FTP prompt, but fully encrypted. You navigate and transfer with familiar commands.
put file— uploadget file— downloadls,cd,pwd— remote navigationlcd,lls— local navigation
sftp deploy@server
sftp> cd /var/www
sftp> put index.html
sftp> get backup.tar.gzWhy rsync Is Different
rsync transfers only the parts of files that changed. On repeat runs it is dramatically faster than scp, making it the tool of choice for backups and deployments.
It also runs over SSH by default for the same encryption.
Basic rsync Usage
The common flag set is -avz:
-a— archive mode (preserves permissions, times, symlinks)-v— verbose-z— compress during transfer
This mirrors a local folder up to the server.
rsync -avz ./site/ deploy@server:/var/www/site/Trailing Slashes Matter
In rsync, a trailing slash on the source changes the result:
src/— copies the contents of src into the destinationsrc— copies the src directory itself into the destination
Getting this wrong creates nested folders, so be deliberate.
rsync -avz src/ dest/ # contents of src into dest
rsync -avz src dest/ # creates dest/src/Mirroring and Excluding Files
--delete makes the destination an exact mirror by removing files not present in the source. Use --exclude to skip paths.
Always combine these with a --dry-run first.
rsync -avz --delete --exclude '.git' --dry-run ./ deploy@server:/var/www/rsync over a Custom SSH Setup
To use a non-standard port or key, pass an explicit ssh command with -e. This integrates with everything you configured in ~/.ssh/config too.
rsync -avz -e 'ssh -p 2222 -i ~/.ssh/deploy_key' ./ deploy@server:/var/www/Best Practices
Transfer files safely and efficiently:
- Use
scpfor quick one-off copies - Use
sftpwhen you need to browse interactively - Use
rsyncfor repeated syncs and backups - Always
--dry-runbefore--delete
Quick Check
Test your secure transfer knowledge.
Recap
You can now move files securely over SSH:
- scp — simple copies (
-r,-P,-i) - sftp — interactive
put/getsessions - rsync — efficient delta syncs with
-avz,--delete,--exclude
All three reuse your existing SSH keys and config, completing your advanced SSH toolkit.
Frequently asked questions
Is the “Secure File Transfer with SCP, SFTP, and rsync” lesson free?
Yes — the full text of “Secure File Transfer with SCP, SFTP, and rsync” is free to read here on the web, and the Linux Server Deployment & SSH Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Server Deployment & SSH Mastery course, upgrade to CoddyKit PRO.
What will I learn in “Secure File Transfer with SCP, SFTP, and rsync”?
Move files between machines over the encrypted SSH channel. Compare scp, sftp, and rsync, learn their key options, and choose the right tool for one-off copies, interactive transfers, and efficient s… You practise Linux Server Deployment & SSH Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Linux Server Deployment & SSH Mastery?
No prior experience is required. Linux Server Deployment & SSH Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Secure File Transfer with SCP, SFTP, and rsync” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Linux Server Deployment & SSH Mastery lesson?
Yes. Every Linux Server Deployment & SSH Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- SSH Port Forwarding (Local/Remote)
- SSH Tunnels and SOCKS Proxy
- SSH Agent and Multi-hop
- Secure File Transfer with SCP, SFTP, and rsync