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. Hi, As i run the ls command in sftp it closes the connection.
    So can you tell that how can i use the ls command in sftp?
    sftp> pwd
    Remote working directory: /incoming
    sftp> ls
    Connection closed

    • @Alok,
      It seems that the user you’re connecting to remote sftp has proper permission to /incoming directory? Please check and confirm..

      • Hi Ravi,
        Thanks for your reply.
        Yes. user has the proper permission. User is the member of a group which has chrootjail configuration. So the user can not move to another directory. Still user is not able to see the list of directories and files in his own directory.

  2. I wanted to know if we have any way to enable the SFTP in ascii mode.I have read online that ascii mode in SFTP is supported sftp v4 onwards, can you please help me to find out as in how can I set the transfer mode to ascii in SFTP??

    Thanks a lot in advance.

    • @Rathi,
      Yes it’s possible….use winscp or ftp client to do so…or you can use command line tricks as described in the article..

  3. Thanks alot. This post helped me move lots of files remotely. I like the simplicity and the approach in whole article. Keep Up!

  4. I want to transfer an entire folder from one linux machine to another linux machine.
    Please let me know the command for the same.

  5. sftp will not pass along a password as a parameter and you cannot script reading the password. You must either manually enter the password or use RSA keys to bypass using passwords. Search for “sftp rsa key password” and you will find many examples of how to do this. (This drove me crazy when I was first learning sftp, I was used to scripting the password for ftp).

    • ssh-keygen -t rsa
      cd .ssh
      u have show the public key
      scp publickey [email protected]:/tmp
      u have cp the torget file have 1777 permessions
      k u have go to another system
      cd .ssh
      cp /tmp/publickey authorized_keys
      service sshd restart
      go to sys1
      ssh sys2
      do not ask the passwd

  6. Hi,

    Generally it will prompt to enter password if we enter SFTP command.
    Is it possible to enter the password into the SFTP command so that I do not see a prompt again asking for password.

    Could you please suggest the syntax,

    My SFTP command is like this, then it will ask for a password say ‘passboss’
    sftp -o StictHostKeyChecking=no -oProxyCommand=’/usr/bin/nc -abcdef.kk.lmmm:1080 %h %p’ [email protected] 22

    Could you please add the password in the above syntax so that it will not prompt again.

    eagerly awaiting ur reponse.



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.