SFTP stands for Secure File Transfer Protocol. It is a command-line tool that enables secure file transfer between a local and remote host. SFTP is a secure alternative to traditional FTP, as it encrypts data before transmitting it over the network. SFTP is commonly used by system administrators to transfer files between servers, as well as by web developers to upload files to a web server.
Overview
The syntax for using the sftp command is as follows:
sftp [options] [user@]host
Once connected to the remote host, you can use a variety of commands to navigate the remote file system and transfer files. The following is a list of common commands:
cd
: Change directory on the remote hostlcd
: Change directory on the local hostls
: List files on the remote hostlls
: List files on the local hostget
: Download a file from the remote hostput
: Upload a file to the remote hostquit
: Exit the SFTP session
Here is an example of how to use the sftp command to transfer a file from a local host to a remote host:
sftp user@remote-host
put local-file remote-file
quit
This will connect to the remote host, upload the local file to the remote host, and then exit the SFTP session.
Options
The following options are available for the sftp command:
Option | Description |
---|---|
-b batchfile |
Batch mode reads a series of commands from a file |
-P port |
Specifies the port to use for the connection |
-o ssh_option |
Specifies an option to pass to ssh |
-s subsystem |
Specifies the SFTP subsystem to use |
Troubleshooting tips
- If you are unable to connect to the remote host, ensure that the SSH service is running on the remote host and that you have the correct login credentials.
- If you receive a “Permission denied” error when attempting to transfer a file, ensure that you have the necessary permissions to read and write to the file on both the local and remote hosts.
- If you encounter a “Connection reset by peer” error, try increasing the timeout value using the
-o
option.
Notes
- SFTP is a secure alternative to traditional FTP, but it is not the same as FTPS, which is another secure file transfer protocol that uses SSL/TLS encryption.
- SFTP uses the SSH protocol for authentication and encryption, which makes it more secure than traditional FTP.
- SFTP is commonly used by system administrators and web developers to transfer files between hosts.