Linux command
sftp 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Connect to a remote server
sftp [user]@[hostname]
Connect using a specific port
sftp -P [port] [user]@[hostname]
Upload a file
sftp> put [local_file] [remote_path]
Download a file
sftp> get [remote_file] [local_path]
Upload a directory recursively
sftp> put -r [local_directory]
Download a directory recursively
sftp> get -r [remote_directory]
List remote directory
sftp> ls
Change remote directory
sftp> cd [remote_path]
说明
sftp is the SSH File Transfer Protocol client, providing secure interactive file transfer over SSH connections. It offers a familiar FTP-like interface while using SSH for authentication and encryption. Unlike FTP, SFTP encrypts all data including credentials and file contents. It uses a single connection (no separate data channel) making it firewall-friendly. The interface supports both interactive use and batch mode (-b) for scripting. Tab completion works for both local and remote paths in most implementations. SFTP can transfer binary and text files without mode switches and preserves file attributes like permissions and timestamps.
参数
- -P _port_
- Connect to specified port (note: uppercase P, unlike ssh)
- -i _identity_file_
- Use specified private key file
- -b _batchfile_
- Batch mode; read commands from file
- -C
- Enable compression
- -r
- Recursively copy directories (with get/put)
- -v
- Verbose mode
- -o _option_
- Pass option to SSH (e.g., -o "ProxyJump=jump-host")
FAQ
What is the sftp command used for?
sftp is the SSH File Transfer Protocol client, providing secure interactive file transfer over SSH connections. It offers a familiar FTP-like interface while using SSH for authentication and encryption. Unlike FTP, SFTP encrypts all data including credentials and file contents. It uses a single connection (no separate data channel) making it firewall-friendly. The interface supports both interactive use and batch mode (-b) for scripting. Tab completion works for both local and remote paths in most implementations. SFTP can transfer binary and text files without mode switches and preserves file attributes like permissions and timestamps.
How do I run a basic sftp example?
Run `sftp [user]@[hostname]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -P _port_ do in sftp?
Connect to specified port (note: uppercase P, unlike ssh)