scp ("secure copy") transfers files over an SSH connection. Its syntax mirrors cp: source and destination, either of which can be user@host:path.
scp file.txt user@host:/tmp/ # local → remote
scp user@host:/tmp/file.txt . # remote → local
scp -r directory/ user@host:/var/ # recurse
scp -P 2222 file host:/tmp/ # non-default port (capital P)
scp host1:/file host2:/file # host → host (via your machine)
OpenSSH 9.0 (2022) switched scp's default transport from the legacy SCP protocol to SFTP internally, addressing long-standing protocol issues. For interactive multi-file work, sftp and rsync are usually better; for one-shot copies scp is still the most direct.
Discussed in:
- Chapter 12: Networking — SSH and Remote Access