scpsftprsync -e sshcurlwget| Tool | Best For |
|---|---|
| scp | A quick, one-off copy between two hosts over SSH |
| sftp | Interactive browsing and transferring, like an FTP session but over SSH |
| rsync | Repeated syncs, especially of large or mostly-unchanged directory trees (see Chapter 7) |
| curl / wget | Downloading a specific file or resource over HTTP(S) or FTP |
# 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 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/
scp uses capital -P for the port; ssh uses lowercase -p.# Start an interactive session
sftp student@server1
| Command (inside sftp) | Action |
|---|---|
ls / lls | List files on the remote / local side |
cd / lcd | Change directory remotely / locally |
pwd / lpwd | Show current directory remotely / locally |
get filename | Download a file from the remote host |
put filename | Upload a file to the remote host |
mget / mput | Download / upload multiple files matching a pattern |
exit / bye | End the session |
cd 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/
# 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
# 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
cd and lcd differ?image.iso.sha256.