Red Hat System Administration II · RH134

Chapter 8

Transferring Files

scp and sftp · rsync over SSH · curl and wget · Verifying transfers
CIS238RH — Mesa Community College
Transfer files securely with scp, sftp, and rsync, retrieve files over HTTP(S) with curl and wget, and verify that a transfer completed correctly.

Key Commands

  • scp
  • sftp
  • rsync -e ssh
  • curl
  • wget
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 MattersThe right tool depends on whether the transfer is one-time or repeated, interactive or scripted, and what protocol the remote end speaks.
# 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/
Tip — scp Is for Simplicity, Not RepetitionFor repeated transfers, or to skip unchanged files, use rsync.
# Use a non-default SSH port
scp -P 2222 report.txt student@server1:/home/student/

# Copy between two REMOTE hosts (on current OpenSSH, traffic
# flows through YOUR machine by default; -R copies directly)
scp student@server1:/home/student/report.txt student@server2:/home/student/
Notescp uses capital -P for the port; ssh uses lowercase -p.
# 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 Localcd changes the remote directory; lcd changes the local one.
# 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 BetterRe-running an interrupted rsync picks up efficiently instead of starting over.
# 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

Without -O, curl writes the download to the screen instead of a file.

# 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 Jobswget is built for downloading and mirroring; curl is a general URL and API tool. Either works for a simple download.
# 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 OneAn interrupted transfer can leave a truncated or corrupted file that looks complete. Verify checksums for anything important.
scp
Secure copy: one-command file transfer between hosts over SSH
sftp
SSH File Transfer Protocol: an interactive transfer session over SSH
curl
General-purpose tool for transferring data to or from a URL
wget
Tool built for downloading files and mirroring content over HTTP(S) or FTP
checksum verification
Confirming a transferred file matches its source by comparing hashes
  1. When would you use sftp instead of scp?
  2. In an sftp session, how do cd and lcd differ?
  3. Why might rsync beat scp for a large file over an unreliable connection?
  4. Which curl option saves a download under its original name?
  5. Which wget option resumes a partial download?
  6. Why isn't checking size or timestamp enough to confirm a file wasn't corrupted?
  7. Write a command that verifies a downloaded file against image.iso.sha256.