We earn commission when you buy through affiliate links.

This does not influence our reviews or recommendations.Learn more.

FTP traffic is unencrypted and insecure which is why it has been mostly replaced by SFTP.

In this article, well cover the usage of SFTP from the command line.

Ill be using an Ubuntu system though commands listed here will work on anyLinux systemwithsftpclient.

you might do pretty much everything with SFTP that you do with SCP.

One such case is usingSCPto push or pull files from a remote server in one go.

Default TCP port 22 should be open for this to work or else explicitly specify the port using-oPortflag.

Im connecting to an SFTP server with IP192.168.1.231.

Once confirmed by typing yes connection proceeds and prompts for a users password.

On a successful connection, youll be shownsftp>prompt.

Check Version

it’s possible for you to check the SFTP version usingversioncommand atsftpprompt.

Getting Help

To get help about available commands and syntax for SFTP, use ?

To show the local systems present working directory uselpwdcommand.

List Files

you’ve got the option to list files in the remote working directory usinglscommand.

To list files in the local working directory, usellscommand.

Switching Directories

Switching the remote working directory can be done usingcdcommand.

Refer example below:

To switch local working directory, uselcdcommand.

Below is a simple example to show usage oflcd.

Upload Files

To upload a single file, useputcommand.

See how I upload localfile1to remote working directory usingputcommand.

I can verify it usinglscommand which prints the content of remote working directory.

To upload multiple files in one go, we can usemputcommand as shown below.

you’re free to use any wildcard or regular expression withmput.

Download Files

Single file using SFTP can be downloaded usinggetcommand.

Im downloading here all files that matches patternremote_file*in remote working directory to my local working directory.

I finally usellscommand to see the downloaded files.

Create Directory

A new directory can be created on a remote server usingmkdircommand.

Remove Directory

An empty remote directory can be removed usingrmdircommand.

Do note that if it is not empty, youll get an error.

Remove File

A remote file can be removed usingrmcommand.

Rename File

A remote file can also be easily renamed usingrenamecommand.

Filesystem Usage

To display statistics for the current directory or filesystem containing path, usedfcommand.

We can use-hflag to show statistics in a human-readable format.

Quit SFTP Session

To quit the SFTP session, use eitherbye,exit,orquitcommand.

Youll be returned to your OS prompt after exiting SFTP.

It offers CLI as well as GUI features and is supported across different platforms.

Refersftpman page for further reading.

If interested in learning more then check out thisUdemy Linux Mastery course.