SCP and SFTP Cheat Sheet

SSH-based file transfer with scp and sftp, including recursive copies, jump hosts, interactive commands, and batch mode.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## scp Basics
Upload a file
scp ./app.tar.gz user@example.com:/tmp/

# Copy a local file to a remote host.

Download a file
scp user@example.com:/var/log/app.log ./

# Copy a remote file to the current directory.

Upload a directory recursively
scp -r ./site/ user@example.com:/var/www/site/

# Copy a full directory tree to a remote host.

Use scp on a custom port
scp -P 2222 ./file.txt user@example.com:/tmp/

# Specify an alternate SSH port for scp.

Use a specific key with scp
scp -i ~/.ssh/id_ed25519 ./file.txt user@example.com:/tmp/

# Specify a private key file for transfers.

Preserve times and mode bits
scp -p ./file.txt user@example.com:/tmp/

# Keep file times and modes during copy.

Use a jump host with scp
scp -J bastion.example.com ./db.dump user@private.internal:/tmp/

# Transfer via a bastion host.

## sftp Basics
Open an SFTP session
sftp user@example.com

# Start an interactive SFTP shell.

Connect to SFTP on a custom port
sftp -P 2222 user@example.com

# Specify a non-default SSH port for SFTP.

Run SFTP in batch mode
sftp -b batch.txt user@example.com

# Execute SFTP commands from a batch file.

Resume an interrupted download
reget backup.tar.gz

# Continue downloading a partially transferred file.

Resume an interrupted upload
reput backup.tar.gz

# Continue uploading a partially transferred file.

Upload within interactive sftp
put ./archive.zip /tmp/archive.zip

# Put a file during an interactive session.

Download within interactive sftp
get /var/log/app.log ./app.log

# Get a file during an interactive session.

Recommended next

No recommendations yet.