10 sFTP Command Examples to Transfer Files on Remote Servers in Linux

File Transfer Protocol (FTP) was a widely used protocol to transfer files or data remotely in an unencrypted format which is not a secure way to communicate.

As we all know that File Transfer Protocol is not at all secure because all transmissions happen in clear text and the data can be readable by anyone during sniffing the packets on the network.

sftp commands
10 sftp command examples

So, basically, FTP can be used in limited cases or on the networks that you trust. Over the period of time, SCP (Secure Copy) and SSH (Secure Shell) addresses this security ambiguity and added an encrypted secure layer while transferring data between remote computers.

[ You might also like: Best Command-Line FTP Clients for Linux ]

SFTP (Secure File Transfer Protocol) runs over SSH protocol on standard port 22 by default to establish a secure connection. SFTP has been integrated into many GUI tools (FileZilla, WinSCP, FireFTP, etc.).

Security Warnings: Please don’t open the SSH port (Secure SHell) globally as this would be a security breach. You can only open for specific IP from where you are going to transfer or manage files on the remote system or vice versa.

This article will guide you to 10 sftp command examples to use through the interactive command-line interface in the Linux terminal.

1. How to Connect to SFTP

By default, the same SSH protocol is used to authenticate and establish an SFTP connection. To start an SFTP session, enter the username and remote hostname or IP address at the command prompt. Once authentication is successful, you will see a shell with an sftp> prompt.

[[email protected] ~]# sftp [email protected]

Connecting to
[email protected]'s password:

2. Getting Help

Once, you are in the sftp prompt, check the available commands by typing ‘?‘ or ‘help‘ at the command prompt.

sftp> ?
Available commands:
cd path                       Change remote directory to 'path'
lcd path                      Change local directory to 'path'
chgrp grp path                Change group of file 'path' to 'grp'
chmod mode path               Change permissions of file 'path' to 'mode'
chown own path                Change owner of file 'path' to 'own'
help                          Display this help text
get remote-path [local-path]  Download file
lls [ls-options [path]]       Display local directory listing
ln oldpath newpath            Symlink remote file
lmkdir path                   Create local directory
lpwd                          Print local working directory
ls [path]                     Display remote directory listing
lumask umask                  Set local umask to 'umask'
mkdir path                    Create remote directory
put local-path [remote-path]  Upload file
pwd                           Display remote working directory
exit                          Quit sftp
quit                          Quit sftp
rename oldpath newpath        Rename remote file
rmdir path                    Remove remote directory
rm path                       Delete remote file
symlink oldpath newpath       Symlink remote file
version                       Show SFTP version
!command                      Execute 'command' in local shell
!                             Escape to local shell
?                             Synonym for help

3. Check Present Working Directory

The command ‘lpwd‘ is used to check the Local present working directory, whereas the pwd command is used to check the Remote working directory.

sftp> lpwd
Local working directory: /
sftp> pwd
Remote working directory: /tecmint/
  • lpwd – print the current directory on your system
  • pwd – print the current directory on the ftp server

4. Listing Files with sFTP

Listing files and directories in local as well as a remote system ftp server.

On Remote
sftp> ls
On Local
sftp> lls

5. Upload File Using sFTP

Put single or multiple files in remote system ftp server.

sftp> put local.profile
Uploading local.profile to /tecmint/local.profile

6. Upload Multiple Files Using sFTP

Putting multiple files on in remote system ftp server.

sftp> mput *.xls

6. Download Files Using sFTP

Getting single or multiple files in a local system.

sftp> get SettlementReport_1-10th.xls
Fetching /tecmint/SettlementReport_1-10th.xls to SettlementReport_1-10th.xls

Get multiple files on a local system.

sftp> mget *.xls

Note: As we can see by default with get command download file in local system with the same name. We can download remote files with a different name by specifying the name at the end. (This applies only while downloading the single file).

7. Switching Directories in sFTP

Switching from one directory to another directory in local and remote locations.

On Remote
sftp> cd test
On Local
sftp> lcd Documents

8. Create Directories Using sFTP

Creating new directories on local and remote locations.

sftp> mkdir test
sftp> lmkdir Documents

9. Remove Directories Using sFTP

Remove directory or file in a remote system.

sftp> rm Report.xls
sftp> rmdir sub1

Note: To remove/delete any directory from a remote location, the directory must be empty.

10. Exit sFTP Shell

The ‘!‘ command drops us in a local shell from where we can execute Linux commands. Type ‘exit‘ command where we can see sftp> prompt return.

sftp> !

[[email protected] ~]# exit
Shell exited with status 1


The SFTP is a very useful tool for administrating servers and transferring files to and from (Local and Remote). We hope this tuts will help you to understand the usage of SFTP to some extent.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

54 thoughts on “10 sFTP Command Examples to Transfer Files on Remote Servers in Linux”

  1. Hey,
    I have two questions.

    1. How can i rename more than one files?
    2. How can i cd with a direct path?

    For example, change from “/export/test” to “/import/test”.

  2. what sftp command do i need to use to download only one file from Multiple files from sftp server?

    For ex: test_1.txt ,
    test_4.txt resides on sftp server. All I would need is download only one file (Any one file)?

  3. I tried to push all folders as well into another server, I did sftp> put *, it transfers all files excluding folder, then i created a folder and tried to sent the files like sftp> put wp-admin/* wp-admin (still it is sending all files of wp-admin to wp-admin excluding all folders). I have tried sftp> put -r foldername and tried get -r as well but i get “invalid flag -r”. I am using terminal, what shall i do ?

  4. Hi Ravi,
    I am trying to use mput command to sftp multiple files with regular expression with below command:

    mput file*

    But this is not working and i have also tried the mput you have given in this article and i am getting an error saying
    “*” not found

    I’m using ksh to run sftp! Please help

    • @Balu,

      You should execute these commands in bash shell only, ksh shell have different switches I think, you need check man pages for this..

  5. Can anyone brief me how MFT is different from SFTP.

    kindly share your valuable inputs on this as we want to migrate the file processing system from SFTP to MFT. Also suggest a few commands in MFT to transfer the files from different servers.

  6. Very nice article. I was researching how to solve a problem with sftp and this article helped me greatly. Thanks.

    Regarding item #10, ‘Exist sFTP Shell’ probably should be ‘Exit sFTP Shell’.

    • @Patrick,

      Thanks for finding this article helpful, and also thanks for notifying us about that typo, corrected in the writeup..

  7. Good morning guys. I’m having an issue with sftp. For some reason, unknown at the moment, sftp just stopped being able to send multiple files at once. I have a bunch of txt files in my folder and I’m running AIX, I can manually put only one at a time, wild cards like *.*, filename.* or even *.txt are no longer accepted. I have to put the full file for sftp to send it. This has been working for 3 months now but just stopped 2 days ago. Does anyone have a clue as to what happened?

  8. I can not seem to input non english characters, such as Å, Ä or Ö (swedish a and o characters), in the linux CLI sftp client. When I try to nothing is printed.

    ls cmd displays files and dirs with these characters just fine, but I can not type in the characters, so entering a dir (cd) or downloading (get) a dir/file with any non english character seems impossible.

    This issue does not exist during a standard ssh shell login, so the locale does not seem to be the problem. It seems to be within the sftp client itself.

    Anyone who has an idea?


Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.