SFTP Command Reference

Every command for the OpenSSH sftp client with syntax and examples - connecting, browsing, transferring, permissions, and batch scripting. Works identically on Windows 10/11, macOS, and Linux, which all ship the OpenSSH client.

Updated October 2026

Connecting to a server

SFTP runs over SSH (port 22 by default), so authentication and host-key verification work exactly like ssh. These flags go on the command line before the session starts:

Command / flagWhat it doesExample
sftp user@hostStart an interactive SFTP session.sftp alice@example.com
-P portConnect to a non-standard port (note: capital P, unlike ssh).sftp -P 2222 alice@example.com
-i keyfileAuthenticate with a specific SSH private key.sftp -i ~/.ssh/deploy_key alice@example.com
-b fileBatch mode - run commands from a file non-interactively.sftp -b upload.txt alice@example.com
-rMake get/put recursive for the whole session.sftp -r alice@example.com
sftp user@host:pathFetch a file directly and exit (no interactive session).sftp alice@example.com:/logs/app.log

If the connection is refused or hangs, verify the server first with the SFTP Connection Tester, and check which authentication methods it accepts with the SFTP Auth Method Checker.

Downloading & uploading

CommandWhat it doesExample
getDownload a file from the server.get report.pdf
get -rDownload a directory and everything in it.get -r backups
putUpload a local file to the server.put site.zip
put -rUpload a directory recursively.put -r dist
mgetDownload multiple files matching a pattern.mget *.log
mputUpload multiple files matching a pattern.mput *.html
regetResume a partially downloaded file.reget big-backup.tar
reputResume a partially uploaded file.reput big-backup.tar
progressToggle the transfer progress meter on/off.progress

There is no ascii/binary toggle - SFTP always transfers files byte-for-byte, so nothing gets corrupted by line-ending conversion.

Batch mode & scripting

For unattended transfers, put commands in a file (one per line) and run sftp in batch mode. Batch mode aborts on the first error and requires key-based authentication - it cannot prompt for a password:

# upload.txt
cd /var/www/site
lcd C:\Projects\site\dist
put -r .
bye
C:\> sftp -b upload.txt -i C:\keys\deploy_key deploy@example.com

This works, but every recurring job means maintaining a script, a key, and a Task Scheduler entry. If you'd rather define "upload this folder every night at 2:00" in a UI - with retries, notifications, and history - that's what FTPie's Scheduled Transfers do.

SFTP on the Windows command line

Windows 10 (1809 and later) and Windows 11 include Microsoft's build of the OpenSSH client in C:\Windows\System32\OpenSSH, so sftp runs in Command Prompt and PowerShell with nothing to install. If Windows answers 'sftp' is not recognized, turn on OpenSSH Client under Settings > Optional features (in Apps on Windows 10, in System on Windows 11), or run Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 in PowerShell as administrator. Everything else on this page works the same; these are the parts that are specific to Windows:

Command / flagWhat it doesExample
ssh -VShow which OpenSSH Windows ships (sftp itself has no version flag).OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2
ssh-keygenMake a key pair for batch mode. It lands in C:\Users\you\.ssh\; give the .pub half to whoever runs the server.ssh-keygen -t ed25519
-i with a Windows pathLog in with that private key.sftp -i C:\keys\id_ed25519 alice@host
-o StrictHostKeyChecking=
accept-new
Store a new server's host key without the yes/no question, so a first unattended run doesn't stop there. A key that has changed is still refused.sftp -o StrictHostKeyChecking=accept-new alice@host
lcd "..."Quote local Windows paths that contain spaces.lcd "C:\My Exports"

A scheduled upload, end to end

Put the commands in C:\Scripts\upload.txt, one per line as in the batch example above, and call sftp from a .bat file. The wrapper lets Task Scheduler run it and leaves a line in a log when a run fails:

@echo off
rem C:\Scripts\upload.bat
sftp -b C:\Scripts\upload.txt -i C:\Users\you\.ssh\id_ed25519 -o StrictHostKeyChecking=accept-new deploy@example.com
if errorlevel 1 (
echo %date% %time% upload failed, exit code %errorlevel% >> C:\Scripts\upload.log
exit /b 1
)

Run it once by hand, then schedule upload.bat; automating FTP and SFTP transfers on Windows walks through the Task Scheduler settings that matter.

What the exit codes mean

Exit codeWhat happenedWhat to do
0Every command in the batch file succeeded.Nothing.
1A command failed, for example cd into a folder that doesn't exist (stat remote: No such file or directory). Nothing after it ran.Fix the command, or put a - in front of it (-rm old.zip) if it is allowed to fail.
255No session at all. Host key verification failed. means the server's key isn't known yet; Permission denied means it tried a password, which batch mode can't type.Connect once by hand or add -o StrictHostKeyChecking=accept-new; log in with a key (-i).

Checked with Windows' own OpenSSH 9.5 against a public test server, October 2026.

Would you rather click than script? Our honest roundup of the best SFTP clients for Windows compares WinSCP, FileZilla, Cyberduck, FTPie and the rest.

About SFTP commands

SFTP (SSH File Transfer Protocol) is not FTP-over-SSH - it is a separate protocol built on the SSH connection layer, defined in the IETF draft-ietf-secsh-filexfer series. The sftp command in Windows, macOS, and Linux is the OpenSSH client implementation, and its command set is what this page documents. Because everything runs inside SSH, one open port (22) carries authentication, commands, and encrypted data - no passive-mode port ranges or TLS certificates to configure.

Coming from classic FTP? The command sets overlap but differ in important ways - see the FTP Command Reference for the ftp.exe and RFC 959 protocol commands.

Common questions

Are SFTP commands the same as FTP commands?

No. SFTP is a different protocol that runs over SSH, and its command set is similar but not identical. Core commands like get, put, cd, ls, and bye work in both, but SFTP adds Unix-style commands such as chmod, ln, and df, uses reget/reput for resuming transfers, and has no ascii/binary mode - every transfer is binary. Commands like mdelete, hash, or literal from classic FTP clients do not exist in sftp.

How do I download or upload an entire folder with SFTP?

Use the -r (recursive) flag: get -r projectfolder downloads a whole directory tree, and put -r projectfolder uploads one. The target directory must not already contain conflicting files. You can also start the session with sftp -r user@host to make transfers recursive by default.

How do I resume an interrupted SFTP transfer?

Use reget filename to resume a partially downloaded file and reput filename to resume an upload. The partial file must still exist on the receiving side; sftp continues from where it stopped instead of starting over.

Does Windows have a built-in SFTP command?

Yes. Windows 10 (1809 and later) and Windows 11 ship the OpenSSH client, so you can run sftp user@host directly from Command Prompt or PowerShell - no extra software needed. The same commands listed on this page work identically on Windows, macOS, and Linux.

How do I script or automate SFTP transfers?

Put one command per line in a text file and run sftp -b batch.txt user@host. Batch mode requires non-interactive authentication, which in practice means setting up SSH key authentication first. For recurring jobs - scheduled uploads, backups, syncs - a client with a built-in scheduler saves you from maintaining scripts and Task Scheduler entries.

Prefer a visual SFTP client?

FTPie is a modern SFTP client for Windows with SSH key authentication, host-key verification, drag-and-drop recursive transfers, and a built-in scheduler - free for up to 3 server connections.

Download FTPie Free