Use Linux SFTP Command to Transfer Files on Remote Servers

SFTP is a protocol that offers a secure and private channel for transfer of files between systems using encryption. A misconception exists about the acronym SFTP, with some thinking it stands for Secure File Transfer Protocol. It stands for SSH File Transfer Protocol. Where in ‘FTPS’ is different, FTPS client will first check if the ftps server’s certificate is trusted and use Secure Sockets Layer protocol (TLS). Good to read on how to Configure VSFTPD SFTP with SSL/TLS on Ubuntu 18.04

One may be forgiven to think that SFTP and FTP are similar in terms of functionality but, the two employ varied protocols. You, therefore, cannot use a standard FTP client to connect to an SFTP server. In this guide, we will focus on the commonly used SFTP commands.

The standard application of SFTP is to run on a command interface within its own environment. That is why in most cases you will notice the program interface changing to the prompt sftp>. The moment you have invoked the SFTP session, the usual system commands will not execute unless you call them using a specific language that is in the SFTP command line standard.

Not all computers can process SFTP commands. You can choose to use the graphical interface version of SFTP or the command line depending on the Operating System you are using. The GUI interface requires you to install an SFTP utility.

In this article, we will take you through some SFTP commands examples that you can use via the unix/linux command line.

How to Connect With SFTP

The SSH protocol used to establish communication are the same as those required by an SFTP channel. Most people prefer to use saved passwords set as defaults, but I would recommend the use of SSH keys that you can use when you need to access any system.

To start an SFTP session, you need a username and the remote hostname. Alternatively, you can use the IP address of the host name at the prompt like shown below:

[email protected]

[email protected]

[email protected]In the above example, if there were a connection that allows the processing of the above command, you would expect a password prompt before gaining access.

1) How to Get Help at the Prompt

If you have no clue on the type or format that can be used on an SFTP command line, use the “?” or “help” at the prompt as follows

sFTP commands

2) Confirm the Working Directory

Using the command lpwd will give more information on the working directory. The pwd is used to check the remote working directory.



3) Listing Files

At the SFTP command prompt, you list both remote and local files using different commands.

Remote listing

Local listing

4) Uploading Files

Uploading can take place by placing single or multiple files on the remote host.

Single file on the remote host use,


Multiple files on the remote host


5) Downloading Files

You will be able to download single or multiple files in a local-path or system.


Download multiple files on a local-path or system


It is evident that when downloading a file in the local system is done using the same name. When you want to use a different name on a remote file download, the name should be specified at the end of the command.

6) Switching Directories

On the remote server, you use the command,

On the local machine, you use the command,

7) Creating directories

Creating directories on both remote and local paths is possible

A new directory on the local path

A new directory on a remote host

8) Removing Directories

Removing a directory or file in remote hosts

Removing a file in remote hosts

Removing directory in remote hosts

Note: This command will only work if the target directory is empty

9) Exiting the Command Shell

The exclamation mark! (known as a command in this case) is used to get out of the SFTP command prompt as shown in the following example.

[email protected]

As simple as it may look like, SFTP is a very powerful tool used for administering servers and managing file transfers between hosts. The utility can be used on both remote and local servers.

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *