Appearance
Secure File Transfer (scp & rsync)
When you’re working with remote servers or cloud machines, you’ll often need to move files back and forth — maybe uploading your simulation code or downloading results. Two simple and reliable ways to do this are scp and rsync.
Both use SSH under the hood, so they’re secure and work seamlessly once your SSH connection is set up.
Let’s look at how to use them in a practical, easy-to-understand way.
Using scp (Secure Copy)
scp is the simpler of the two — think of it as “copy-paste over SSH.” It lets you copy files between your local system and a remote server safely.
Upload a file from local to remote
bash
scp myscript.py username@server_ip:/home/username/This copies myscript.py from your computer to the remote server.
Download a file from remote to local
bash
scp username@server_ip:/home/username/output.txt ~/Downloads/This downloads output.txt from the server into your local Downloads folder.
Copy entire folders
Add the -r flag (for recursive copy):
bash
scp -r results/ username@server_ip:/home/username/That will copy your entire results folder to the server.
Tip: You can use either IP address or hostname (if you’ve set up an SSH config alias like
myserver).
Using rsync (for smarter transfers)
rsync works like scp, but it’s smarter — it only copies what’s new or changed. So if you’re transferring large folders (like simulation outputs or datasets), rsync saves time and bandwidth.
Basic upload example
bash
rsync -avz myproject/ username@server_ip:/home/username/myproject/Basic download example
bash
rsync -avz username@server_ip:/home/username/results/ ./results/Here’s what the flags mean:
-a→ preserves folder structure and permissions-v→ verbose (shows progress)-z→ compresses data during transfer (faster)
Pro Tip: You can add
--progressto see live transfer updates:bashrsync -avz --progress ./data/ username@server_ip:/home/username/
Practical Example
Imagine you’ve finished a simulation on your cloud server and want to bring the results back:
bash
rsync -avz username@server_ip:/home/username/post-processing/output/ ./local_output/This will copy everything inside the remote output/ folder to a local folder called local_output, only transferring new or changed files if you rerun it later.
Notes
Both
scpandrsyncuse SSH, so they’re already secure — no need for passwords if you’ve set up SSH keys.Use
rsyncfor big or repeated transfers — it’s faster and smarter.Always double-check the paths before running — especially if using
-r(it can overwrite things).If your remote port isn’t the default (22), you can specify it:
bashscp -P 2222 file.txt user@server_ip:/home/user/ rsync -avz -e "ssh -p 2222" folder/ user@server_ip:/home/user/To pause and resume large transfers,
rsynccan pick up exactly where it left off —scpcannot.
Summary
scpis perfect for quick, one-time file transfers between your local machine and a remote server.rsyncis ideal for large directories or repeated transfers, as it only copies what’s new or changed.- Both tools run securely over SSH, so there’s no extra setup once your SSH keys are ready.
With these two simple commands, you can move data between your laptop and remote servers effortlessly — no external tools, no fuss, just fast and reliable transfers.