Menu Desplegable

How to Use Linux SFTP Command to Transfer Files.

SFTP (SSH File Transfer Protocol) is a secure file protocol used to access, manage, and transfer files over an encrypted SSH transport.

When compared with the traditional FTP protocol, SFTP offers all the functionality of FTP, and it is easier to configure.

Unlike the scp command, which only allows file transfers, the sftp command allows you to perform a range of operations on remote files and resume file transfers.

Before you Begin

To be able to transfer and manage files via SFTP you must have write permission on the remote system.

When transferring large files, it is recommended to run the sftp command inside a screen or tmux session.

The directory from where you run the sftp command is the local working directory.

Establishing an SFTP connection SFTP works on a client-server model. It is a subsystem of SSH and supports all SSH authentication mechanisms.

Although the traditional password authentication is set up by default and easier to use, if you regularly connect to your server via SSH/SFTP it is recommended to create SSH keys and set up a passwordless SFTP login.

To open an SFTP connection to a remote system, use the sftp command followed by the remote server username and the IP address or domain name:

sftp remote_username@server_ip_or_hostname

If you are connecting to a host using password authentication you will be prompted to enter the user password.

Downloading Files with the SFTP Command

To download a single file from the remote server, use the get command:


The output should look something like this:

Fetching /home/remote_username/ to
/home/remote_username/                           100%   29MB   1.8MB/s   00:18

If you want to save the downloaded file with a different name, specify the new name as the second argument:


To download a directory from the remote system, use the recursive -r option:

get -r remote_directory

If a file transfer fails or is interrupted, you can resume it using the reget command.

The syntax of reget is the same as the syntax of get:


Uploading Files with the SFTP Command

To upload a file from the local machine to the remote SFTP server, use the put command:


The output should look something like this:

Uploading to /home/remote_username/                          100%   13MB   1.9MB/s   00:16

If the file you want to upload is not located in your current working directory, use the absolute path to the file.

When working with put you can use the same options that are available with the get command.

To upload a local directory, you would type:

put -r locale_directory

To resume an interrupted upload: