sftp Command
Intermediate SSH & Remote man(1)Secure File Transfer Protocol (interactive)
👁 10 views
📅 Updated: Mar 15, 2026
SYNTAX
sftp [OPTION]... [USER@]HOST
What Does sftp Do?
sftp (SSH File Transfer Protocol) provides interactive file transfer over an encrypted SSH connection. It offers an FTP-like interface with the security of SSH, supporting file uploads, downloads, directory navigation, and remote file management.
Unlike FTP which sends data in clear text, sftp encrypts everything through the SSH connection. It supports key-based authentication, uses the same credentials as SSH, and works through SSH tunnels.
sftp is ideal for interactive file management on remote servers, bulk file transfers, and situations where you need to browse the remote filesystem before deciding what to transfer.
Unlike FTP which sends data in clear text, sftp encrypts everything through the SSH connection. It supports key-based authentication, uses the same credentials as SSH, and works through SSH tunnels.
sftp is ideal for interactive file management on remote servers, bulk file transfers, and situations where you need to browse the remote filesystem before deciding what to transfer.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -P | Connect to specific port | sftp -P 2222 user@server |
| -i | Use specific identity key | sftp -i ~/.ssh/key.pem user@server |
| -b | Batch mode — read commands from file | sftp -b commands.txt user@server |
| -r | Recursive operations (used with get/put) | sftp> get -r /remote/dir |
| -C | Enable compression | sftp -C user@server |
| -l | Limit bandwidth in Kbit/s | sftp -l 5000 user@server |
Practical Examples
#1 Connect to server
Opens interactive SFTP session. Type help for available commands.
$ sftp user@server.example.com
Output:
sftp>
#2 Upload a file
Uploads a local file to the remote server.
$ sftp> put report.pdf /var/www/uploads/#3 Download a file
Downloads a remote file to the local machine.
$ sftp> get /var/log/app.log ./local-copy.log#4 Upload directory recursively
Uploads an entire directory tree.
$ sftp> put -r ./project /var/www/html/#5 Navigate and list
Navigate and list files on the remote server.
$ sftp> cd /var/www\nsftp> ls -la#6 Batch transfer
Executes SFTP commands from a file for automated transfers.
$ sftp -b batch.txt user@serverTips & Best Practices
Common SFTP commands: put (upload), get (download), ls (list), cd (change dir), lcd (change local dir), mkdir, rm, rename, bye/exit (quit).
sftp vs scp vs rsync: sftp is interactive (browse and select files). scp is for quick non-interactive copies. rsync is for incremental synchronization. Choose based on your workflow.
Not the same as FTPS: sftp (SSH FTP) and FTPS (FTP over SSL) are completely different protocols. sftp uses SSH port 22; FTPS uses FTP ports 21/990.
Frequently Asked Questions
How do I upload files via SFTP?
Connect with sftp user@server, navigate with cd, then use put filename to upload. For directories, use put -r dirname.
How do I automate SFTP transfers?
Create a batch file with SFTP commands and use sftp -b batchfile.txt user@server. Or use scp/rsync for simpler scripting.
What is the difference between sftp and FTP?
SFTP is encrypted (runs over SSH). FTP sends data including passwords in clear text. Always prefer SFTP over FTP for security.
Related Commands
More SSH & Remote Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →