sftp Command: Tutorial & Examples
Transfer files to or from a remote host using the Secure File Transfer Protocol (SFTP)
The sftp
command in Linux is used to securely transfer files and directories between two different systems over a network connection using the SFTP (Secure File Transfer
Protocol) protocol. It is similar to the FTP (File Transfer Protocol) command, but uses SSH (Secure Shell) for secure transfer of files.
The basic syntax for using the sftp command is as follows:
sftp [user@]host
When you run the sftp
command, it will open an interactive session where you can use various commands such as put
, get
, ls
, cd
, mkdir
etc. to transfer files or navigate
the file system.
Here are a few examples of how the sftp
command can be used:
Connect to a remote host and upload a file named file.txt
:
sftp user@remote-host
sftp> put file.txt
Connect to a remote host and download a file named file.txt
:
sftp user@remote-host
sftp> get file.txt
sftp
uses the same authentication and security mechanisms as ssh
, and it can be configured to use specific ssh key, and it's also possible to specify a
different ssh
port by providing it as an argument when calling the command.
It's worth noting that sftp
is a more secure alternative to FTP, and it provides a more user-friendly interface for transferring files and directories between systems. Because it
uses the SSH protocol, the data and authentication process is encrypted, which ensures that your data is protected while in transit.