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

File Transfer Protocol (FTP) was widely used protocol to transfer files or data remotely in unencrypted format which is not secure way to communicate. As we all know that File Transfer Protocol is not at all secure because all transmissions happens in clear text and the data can be readable by anyone during sniffing the packets on the network.

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 and SSH addresses this security ambiguity and added an encrypted secure layer while transferring data between remote computers.

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

This article will guide you 10 sftp command examples to use it through interactive command-line interface.

1. How to Connect to SFTP

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

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

7. Switching Directories

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

On Remote

sftp> cd test
sftp>

On Local

sftp> lcd Documents

8. Create Directories

Creating new directories on local and remote locations.

sftp> mkdir test

sftp> lmkdir Documents

9. Remove Directories

Remove directory or file in remote system.

sftp> rm Report.xls

sftp> rmdir sub1

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

10. Exist sFTP Shell

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

sftp> !
[root@sftp ~]# exit
Shell exited with status 1
sftp>

Conclusion

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 in some extent.

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
ls
u have show the public key
scp publickey oracle@sys2:/tmp
u have cp the torget file have 1777 permessions
k u have go to another system
cd .ssh
ls
cp /tmp/publickey authorized_keys
service sshd restart
go to sys1
ssh sys2
do not ask the passwd