SFTP Cheatsheet
Quick reference for the Linux sftp client, covering login, navigation, transfers, and remote file management over SSH
SFTP is a secure file transfer client that runs over SSH. This cheatsheet covers the most common interactive commands for connecting to a remote server, moving files in both directions, and managing permissions inside an active session.
Connect and Authenticate
Open an SFTP session against a remote host.
| Command | Description |
|---|---|
sftp user@hostname | Connect to remote server |
sftp user@192.168.1.10 | Connect by IP |
sftp -P 2222 user@hostname | Connect to a custom SSH port |
sftp -i ~/.ssh/id_ed25519 user@hostname | Connect with a specific key |
sftp -b commands.txt user@hostname | Run commands from a batch file |
quit | Quit session |
bye | Quit session (alias for quit) |
Local and Remote Paths
Navigate directories on both sides of the session.
| Command | Description |
|---|---|
pwd | Show remote working directory |
lpwd | Show local working directory |
cd /remote/path | Change remote directory |
lcd /local/path | Change local directory |
ls | List remote files |
lls | List local files |
ls -la | Long listing of remote files |
Download Files
Pull files from the remote server to the local system.
| Command | Description |
|---|---|
get file.txt | Download one file |
get remote.txt local.txt | Download and rename locally |
get -r remote_dir | Download a directory recursively |
get -P file.txt | Preserve file permissions and timestamps |
mget *.log | Download multiple files matching a pattern |
reget large.iso | Resume an interrupted download |
Upload Files
Push local files to the remote server.
| Command | Description |
|---|---|
put file.txt | Upload one file |
put local.txt remote.txt | Upload with a remote name |
put -r local_dir | Upload a directory recursively |
put -P file.txt | Preserve permissions and timestamps |
mput *.txt | Upload multiple files |
reput large.iso | Resume an interrupted upload |
Remote File Management
Manage files and directories on the SFTP server.
| Command | Description |
|---|---|
mkdir dirname | Create remote directory |
rmdir dirname | Remove empty remote directory |
rm file.txt | Delete remote file |
rename old.txt new.txt | Rename remote file |
ln source link | Create a hard link on the remote |
ln -s source link | Create a symbolic link on the remote |
df -h | Show remote filesystem usage |
Permissions and Ownership
Adjust permissions and ownership on remote files.
| Command | Description |
|---|---|
chmod 644 file.txt | Change remote file mode |
chown 1000 file.txt | Change remote owner by UID |
chgrp 1000 file.txt | Change remote group by GID |
umask 022 | Set default permission mask |
Session Helpers
Inspect and control the active session.
| Command | Description |
|---|---|
!command | Run a local shell command |
! | Drop into a local shell |
version | Show SFTP protocol version |
progress | Toggle transfer progress meter |
help or ? | List available SFTP commands |
Non-Interactive and Scripting
Use SFTP from scripts and automated jobs.
| Command | Description |
|---|---|
sftp -b script.txt user@host | Run a batch file of commands |
sftp -q user@host | Quiet mode (suppress banner and progress) |
sftp -o IdentityFile=key user@host | Pass any ssh_config option |
echo "get file.txt" | sftp -b - user@host | Pipe commands via stdin |