Copying Files Remotely
Scp and rsync.
Now that you can reach a server, you'll want to move files back and forth. Upload a website, download a log. Two commands do it, both built on top of SSH.

- Move files back and forth
- Upload, download
- Both use SSH
Copying with scp
SCP works just like CP, but a path can include a server, with a colon. Here we upload todo dot TXT, to the server's home folder. Then we download the server's notes, and save them as server notes. Because we have keys, no password is needed.
scp todo.txt sam@server: ssh sam@server ls notes.txt site todo.txt scp sam@server:notes.txt server-notes.txt cat server-notes.txt Server notes
Syncing with rsync
R sync is smarter. It only copies what's changed, so it's perfect for keeping a folder in sync, like a website. Dash A keeps permissions and dates, and dash V lists each file. Run it a second time, and it copies nothing, because nothing changed.
rsync -av Documents/ sam@server:backup/ sending incremental file list created directory backup ./ cv.txt report.txt sent 274 bytes received 86 bytes 240.00 bytes/sec total size is 103 speedup is 0.29 rsync -av Documents/ sam@server:backup/ sending incremental file list sent 78 bytes received 12 bytes 180.00 bytes/sec total size is 103 speedup is 1.14
scp or rsync?
Use SCP for a quick, one off copy of a file or two. Use R sync for folders, backups, and anything you'll copy again. And watch the slash at the end of a folder name in R sync. Documents with a slash copies what's inside the folder. Without the slash, it copies the folder itself.
| key | value |
|---|---|
| scp file user@host: | quick copy |
| scp user@host:file . | download |
| rsync -av dir/ host:dir/ | sync a folder |
| Trailing / | contents, not the folder |
Summary
SCP copies files to and from servers, and R sync keeps folders in sync, copying only what changed. Next, seeing which programs are listening on the network.
Key takeaways- scp
- rsync -av
- Both use SSH keys