Three tools, three cases
- scp — old, simple, ssh-based copy. Good for one-shot single-file pushes/pulls.
- rsync — covered last lesson. Smart sync; the everyday choice.
- sftp — interactive ftp-like client over ssh. Good for browsing a remote tree without mounting it.
scp essentials
scp file.txt user@host:/path/ # local → remote
scp user@host:/path/file.txt . # remote → local
scp -r dir/ user@host:/path/ # recursive
scp -P 2222 file.txt user@host: # custom port (capital P!)Note: capital -P for port (lowercase -p means preserve perms, opposite of ssh's -p).
scp deprecation note
OpenSSH has been moving to use SFTP under the hood for scp since 9.0; behavior is mostly the same but a few flags differ. For new scripts, prefer rsync or sftp. Old scp continues to work.
sftp interactive
sftp user@host
sftp> pwd
sftp> ls
sftp> cd /var/log
sftp> get app.log # download
sftp> put local.txt # upload
sftp> byeWhen to use which
- One file, both locations clear →
scpis fine. - Multiple files, repeat operations, want resume + delta →
rsync. - Need to browse the remote tree by hand, decide what to download →
sftp. - Need a mounted directory →
sshfs(brew install macfuse+ sshfs, fragile but exists).