Skip to main content

SFTP Cheatsheet

By Dejan Panovski Updated on Download PDF

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.

CommandDescription
sftp user@hostnameConnect to remote server
sftp user@192.168.1.10Connect by IP
sftp -P 2222 user@hostnameConnect to a custom SSH port
sftp -i ~/.ssh/id_ed25519 user@hostnameConnect with a specific key
sftp -b commands.txt user@hostnameRun commands from a batch file
quitQuit session
byeQuit session (alias for quit)

Local and Remote Paths

Navigate directories on both sides of the session.

CommandDescription
pwdShow remote working directory
lpwdShow local working directory
cd /remote/pathChange remote directory
lcd /local/pathChange local directory
lsList remote files
llsList local files
ls -laLong listing of remote files

Download Files

Pull files from the remote server to the local system.

CommandDescription
get file.txtDownload one file
get remote.txt local.txtDownload and rename locally
get -r remote_dirDownload a directory recursively
get -P file.txtPreserve file permissions and timestamps
mget *.logDownload multiple files matching a pattern
reget large.isoResume an interrupted download

Upload Files

Push local files to the remote server.

CommandDescription
put file.txtUpload one file
put local.txt remote.txtUpload with a remote name
put -r local_dirUpload a directory recursively
put -P file.txtPreserve permissions and timestamps
mput *.txtUpload multiple files
reput large.isoResume an interrupted upload

Remote File Management

Manage files and directories on the SFTP server.

CommandDescription
mkdir dirnameCreate remote directory
rmdir dirnameRemove empty remote directory
rm file.txtDelete remote file
rename old.txt new.txtRename remote file
ln source linkCreate a hard link on the remote
ln -s source linkCreate a symbolic link on the remote
df -hShow remote filesystem usage

Permissions and Ownership

Adjust permissions and ownership on remote files.

CommandDescription
chmod 644 file.txtChange remote file mode
chown 1000 file.txtChange remote owner by UID
chgrp 1000 file.txtChange remote group by GID
umask 022Set default permission mask

Session Helpers

Inspect and control the active session.

CommandDescription
!commandRun a local shell command
!Drop into a local shell
versionShow SFTP protocol version
progressToggle transfer progress meter
help or ?List available SFTP commands

Non-Interactive and Scripting

Use SFTP from scripts and automated jobs.

CommandDescription
sftp -b script.txt user@hostRun a batch file of commands
sftp -q user@hostQuiet mode (suppress banner and progress)
sftp -o IdentityFile=key user@hostPass any ssh_config option
echo "get file.txt" | sftp -b - user@hostPipe commands via stdin

Other ways to move files between systems.

ToolDescription
scpSecure copy over SSH
rsyncEfficient sync and incremental transfer
sshUnderlying secure shell protocol
ftpLegacy unencrypted file transfer