sftp
Quick Reference
Command Name:
sftp
Category:
networking
Platform:
Linux/Unix
Basic Usage:
Common Use Cases
- 1
Interactive file transfer
Transfer files securely with an interactive command-line interface
- 2
Remote file management
Create, delete, and organize files on remote servers
- 3
Automated scripts
Use batch mode for automated file transfers in scripts
- 4
Web development
Upload and manage website files on hosting servers
Syntax
sftp [OPTION] [[user@]host[:file [file]]]
Options
Option | Description |
---|---|
-1 | Use protocol version 1 (deprecated) |
-4 | Force use of IPv4 addresses |
-6 | Force use of IPv6 addresses |
-B buffer_size | Specify buffer size for transfers (default: 32768 bytes) |
-b batchfile | Batch mode - read commands from the specified file |
-C | Enable compression |
-D sftp_server_path | Connect directly to a local sftp server (rather than via ssh) |
-F ssh_config | Specify an alternative SSH configuration file |
-i identity_file | Specify the file from which the identity (private key) is read |
-l limit | Limit bandwidth in Kbit/s |
-o ssh_option | Pass options to ssh in the format used in ssh_config |
-P port | Specify the port to connect to on the remote host |
-p | Preserve modification times, access times, and modes from the original file |
-q | Quiet mode - disable progress meter and warning/diagnostic messages |
-R num_requests | Specify the number of outstanding requests (default: 64) |
-r | Recursively copy entire directories |
-S program | Specify the path to the ssh program |
-v | Verbose mode - display debugging messages |
Examples
How to Use These Examples
The examples below show common ways to use the sftp
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
sftp user@remote_host
Connect to a remote SFTP server.
sftp user@remote_host:file.txt
Connect to a remote server and immediately download the specified file.
sftp -P 2222 user@remote_host
Connect to a remote server using a non-standard SSH port (2222).
Advanced Examples:
# After connecting with sftp:
get file.txt # Download a file
put local_file.txt # Upload a file
get -r remote_dir/ # Download a directory recursively
put -r local_dir/ # Upload a directory recursively
ls # List remote files
lls # List local files
cd /remote/path # Change remote directory
lcd /local/path # Change local directory
mkdir newdir # Create remote directory
rm file.txt # Delete remote file
rmdir dir # Delete remote directory
exit # Quit SFTP session
Common SFTP interactive commands after establishing a connection.
sftp -b batch_file.txt user@remote_host
Execute SFTP commands in batch mode from a file.
sftp -i ~/.ssh/private_key user@remote_host
Connect using a specific identity file (private key) for authentication.