Chapter Objective: Transfer files securely between systems using scp, sftp, and rsync, retrieve files over HTTP(S) with curl and wget, and verify a transfer completed correctly.

Key commands: scp, sftp, rsync -e ssh, curl, wget

Transfer Methods at a Glance

ToolBest For
scpA quick, one-off copy between two hosts over SSH
sftpInteractive browsing and transferring, like an FTP session but over SSH
rsyncRepeated syncs, especially of large or mostly-unchanged directory trees (see Chapter 7)
curl / wgetDownloading a specific file or resource over HTTP(S) or FTP
🔵 Why It Matters All four tools solve "get data from here to there," but the right choice depends on whether the transfer is one-time or repeated, interactive or scripted, and what protocol the far end actually speaks.

scp: Quick Copies Over SSH

# Copy a local file TO a remote host
scp report.txt student@server1:/home/student/

# Copy a file FROM a remote host to the local system
scp student@server1:/home/student/report.txt .

# Copy a directory recursively
scp -r project/ student@server1:/home/student/

# Use a non-default SSH port
scp -P 2222 report.txt student@server1:/home/student/

# Copy directly between two REMOTE hosts (traffic still flows through YOUR machine unless -3 is adjusted)
scp student@server1:/home/student/report.txt student@server2:/home/student/
✅ Tip — scp Is for Simplicity, Not Repetition scp is ideal for a single, quick file move. For anything that runs repeatedly or needs to skip unchanged files, rsync (Chapter 7) is almost always the better choice — it avoids re-transferring data that hasn't changed.

sftp: Interactive File Transfer

Unlike scp's single-command style, sftp opens an interactive session — useful when you need to browse around before deciding what to transfer.

# Start an interactive session
sftp student@server1
Command (inside sftp)Action
ls / llsList files on the remote / local side
cd / lcdChange directory remotely / locally
pwd / lpwdShow current directory remotely / locally
get filenameDownload a file from the remote host
put filenameUpload a file to the remote host
mget / mputDownload / upload multiple files matching a pattern
exit / byeEnd the session
🔵 Note — The "l" Prefix Means Local Nearly every sftp command has a local-side counterpart prefixed with lcd changes the remote directory, lcd changes yours. Mixing these up is a common source of "why did that go to the wrong place" confusion.

rsync Over SSH

Chapter 7 covered rsync for archiving; the same tool doubles as a secure transfer mechanism, since it uses SSH as its transport by default when a remote host is involved.

# Sync a local directory TO a remote host over SSH
rsync -av /home/student/project/ student@server1:/backups/project/

# Explicitly specify SSH and a non-default port
rsync -av -e "ssh -p 2222" /home/student/project/ student@server1:/backups/project/
✅ Tip — rsync Resumes Interrupted Transfers Better If a large transfer is interrupted partway through, re-running the same rsync command picks up efficiently rather than starting over — a real advantage over scp for big files on unreliable connections.

Downloading with curl and wget

# Download a file, saving it with its original name
wget https://example.com/files/release-notes.pdf

# Download and save with curl (curl needs -O to keep the original filename)
curl -O https://example.com/files/release-notes.pdf

# Resume a partially completed download
wget -c https://example.com/files/large-iso.iso

# Follow redirects with curl (off by default, unlike wget)
curl -L -O https://example.com/redirecting-link

# Show only headers, useful for checking a file's size before downloading
curl -I https://example.com/files/large-iso.iso
🔵 Note — Different Defaults, Similar Jobs wget is purpose-built for downloading and recursion (mirroring whole sites); curl is a more general-purpose tool for interacting with URLs and APIs, including uploads, custom headers, and non-GET requests. For a simple one-off download, either works fine.

Verifying Transferred Files

# Compare file sizes and timestamps quickly
ls -l report.txt

# Compare checksums between source and destination
sha256sum report.txt

# If the source published an official checksum file, verify against it
sha256sum -c release-notes.pdf.sha256
⚠️ Warning — A Successful Transfer Isn't Automatically a Correct One Network interruptions can occasionally leave a truncated or corrupted file behind that still "looks" transferred. For anything important — installers, backups, security-sensitive downloads — verify a checksum rather than assuming completion means correctness.

Key Terms for Chapter 8

scp
Secure copy; transfers files between hosts over SSH with a single command
sftp
SSH File Transfer Protocol; provides an interactive file-browsing and transfer session
curl
General-purpose tool for transferring data to or from a URL
wget
Tool purpose-built for downloading files and mirroring content over HTTP(S)/FTP
checksum verification
Confirming a transferred file matches its source exactly, via a computed hash

Review Questions

  1. When would you reach for sftp instead of scp?
  2. Inside an sftp session, what is the difference between cd and lcd?
  3. Why might rsync be a better choice than scp for transferring a large file over an unreliable connection?
  4. What flag does curl need to save a downloaded file under its original name, given that curl doesn't do this by default?
  5. What flag lets wget resume a partially completed download instead of starting over?
  6. Why is checking a file's size or timestamp after a transfer not sufficient to confirm it wasn't corrupted?
  7. Write a command that verifies a downloaded file against a checksum file named image.iso.sha256.