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?
| Remote | Local | Purpose |
|---|---|---|
pwd | lpwd | Print current folder |
cd dir | lcd dir | Change folder |
ls -la | lls -la | List files |
mkdir dir | lmkdir dir | Create a folder |
lumask 022 | Set 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?
| Command | Effect |
|---|---|
get remote [local] | Download a file |
get -r dir | Download a folder tree |
get -p file | Keep times and permissions |
get -a file / reget file | Resume a partial download |
put local [remote] | Upload a file |
put -r dir | Upload a folder tree |
put -a file / reput file | Resume a partial upload |
get -f file, put -f file | Call fsync after transfer so data reaches disk |
mget, mput | Aliases 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.copyorcp 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?
| Flag | Purpose |
|---|---|
-P port | SSH port |
-i key | Identity file |
-b file | Batch mode from a file of commands |
-r | Recursive by default for get and put |
-l limit | Bandwidth limit in Kbit/s |
-R num, -B bytes | Outstanding requests and buffer size |
-J host | Jump 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.
OpenHow SFTP works
Inside SFTP: the SSH subsystem request, protocol version 3, handles and request ids, pipelined reads and the OpenSSH extensions.
OpenThe 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.
OpenWhat 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.
OpenFAQ
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.