How-to

SFTP Commands Reference

The sftp prompt has a compact command set. This reference groups it by job, with the options that make each command more useful.

How are sftp commands organized?

Commands at the sftp> prompt act on the remote machine; versions starting with l act on your local side. Paths may be absolute or relative to the current folder on each side. Type help or ? at the prompt for the built-in list. Connecting is covered in Use SFTP step by step.

Which commands move around?

RemoteLocalPurpose
pwdlpwdPrint current folder
cd dirlcd dirChange folder
ls -lalls -laList files
mkdir dirlmkdir dirCreate a folder
lumask 022Set the local umask for downloads

Remote ls understands -l for details, -a for hidden files, -h for readable sizes, -t and -S for sorting by time or size, and -r to reverse the order.

Which commands transfer files?

CommandEffect
get remote [local]Download a file
get -r dirDownload a folder tree
get -p fileKeep times and permissions
get -a file / reget fileResume a partial download
put local [remote]Upload a file
put -r dirUpload a folder tree
put -a file / reput fileResume a partial upload
get -f file, put -f fileCall fsync after transfer so data reaches disk
mget, mputAliases of get and put, kept for FTP habits

Wildcards such as get *.csv expand on the remote side; put *.csv expands locally. progress toggles the progress bar, handy to silence it in logged sessions.

Which commands manage files on the server?

sftp> rename draft.txt final.txt
sftp> rm old-export.csv
sftp> rmdir empty-folder
sftp> chmod 640 settings.ini
sftp> chgrp 1003 shared.xlsx
sftp> chown 1001 handover.pdf
sftp> ln -s /srv/releases/2026-12-03 current

Note that chown and chgrp take numeric IDs, not names, and only work if the server allows them, which normally means logging in as root. rename replaces an existing target atomically when the server supports the posix-rename extension, as OpenSSH does. ln without -s creates a hard link where supported.

What else is available?

  • df -h: free space on the remote file system, through the statvfs extension.
  • copy or cp src dst: server-side copy on recent OpenSSH, without sending data over the network.
  • !command: run a local shell command, such as !sha256sum file; a bare ! opens a local shell.
  • version: show the protocol version in use.
  • bye, exit, quit: end the session.

Which command-line flags matter?

FlagPurpose
-P portSSH port
-i keyIdentity file
-b fileBatch mode from a file of commands
-rRecursive by default for get and put
-l limitBandwidth limit in Kbit/s
-R num, -B bytesOutstanding requests and buffer size
-J hostJump through a bastion

You can also start directly in a folder: sftp ops@203.0.113.25:/srv/exports/, or fetch a single file without the prompt: sftp ops@203.0.113.25:/srv/exports/orders.csv ./.

How do I make a batch job tolerant of small failures?

In batch mode, sftp stops at the first error. Prefix a command with - to ignore its failure, for example -rm *.tmp when there may be nothing to remove, and @ to suppress echoing it. The rest of the job continues, and the exit status reflects only commands without the prefix.

The protocol behind these commands is explained in How SFTP works; limiting what an SFTP user can reach is in SFTP vs SSH.

How do I check what the server supports?

Run sftp -vv and look for the extension list in the debug output after login. Commands such as df, cp, atomic rename and hard links depend on those extensions; on servers that lack them, the client reports that the operation is not supported instead of failing silently.

Remember that every command runs with the rights of the account you logged in as. If put fails with "Permission denied", the folder belongs to someone else; ask for write access to a dedicated upload folder rather than broader rights.

Keep Reading

Use SFTP step by step

Connect, browse, upload, download and resume with the sftp client, run batch jobs and use graphical clients on Windows and macOS.

Open

How SFTP works

Inside SFTP: the SSH subsystem request, protocol version 3, handles and request ids, pipelined reads and the OpenSSH extensions.

Open

The scp command

Copy files between machines with scp: ports, folders, preserved times, speed limits, jump hosts, remote-to-remote copies and when rsync is better.

Open

What is SFTP?

The SSH File Transfer Protocol in plain terms: what it secures, how it compares with FTP, FTPS and SCP, and where it fits on a server.

Open

FAQ

Quick Answers

Use lls; commands starting with l act on the local side.

Use reget, or get -a, with the file name.

Run df -h at the sftp prompt.

The sftp chown and chgrp commands take numeric user and group IDs, not names.

Prefix it with an exclamation mark, such as !ls -la.