Glossary

How to Use SFTP (SSH File Transfer Protocol)

FTP is the standard method of transferring files and data between computers, but it’s becoming more and more outdated in today’s security-conscious environment.

FTP was designed in an era when data security was not a big concern. FTP transfers unencrypted data between different machines over a network. Valuable information such as user names and passwords can easily be read by anyone that can perform packet capture on the system. This security flaw in FTP resulted in the emergence of the SSH File Transfer Protocol (SFTP).

SFTP is a method of transferring data over an SSH channel and works as a subsystem of SSH.  This is particularly useful for VPS users! It’s the only file transfer protocol that protects against attacks at any point in the data transfer process, making it the preferred protocol.

FTP has two different channels to exchange data, the command channel and the data channel. In contrast, SFTP has only one encrypted channel where the data is exchanged in encrypted, formatted packets.

Working with SFTP

Let’s learn the basic sftp uses:

Connecting to a Remote Server Using SFTP

The syntax for connecting to a remote server via SFTP on Linux distribution is:

sftp user@ip-address or domain.com

If we wanted to connect to a Linux VPS servers with the IP 31.220.57.32 via SFTP we would use the command:

sftl user@31.220.57.32

After this command, you are connected successfully to the remote server.

Transfering Files from a Remote Server to the Local Machine Using SFTP

Now, let’s see how to transfer a file from a remote server to your local machine using the get command. The basic syntax of the get command is:

get /remote-directory/file.txt

To copy the /etc/xinetd.conf file from the remote server (31.220.57.32) to your local machine you would use the command:

get /etc/xinetd.conf

After the download, you can find the xinetd.conf file in the /user/home directory of your local machine.

To download multiple files use the mget command. Let’s download all files in a directory called /etc that have the .conf extension.

mget /etc/*.conf

After the download, you can find all *.conf files in /user/home directory of your local machine.

Transfering Files from the Local Machine to a Remote Server Using SFTP

To copy a file from the local machine (SFTP connected) to the remote server use the get command. The syntax of get command is

get file.txt /RemoteDirectory

Here’s how to transfer the file example.txt from a local machine to the remote machine:

put /home/edward/example.txt /root

Here we will find the file in the destination machine’s (remote server’s) root directory.

You can also try transferring multiple files using the mput command. It works nearly the same as mget:

mput/home/edward/*.txt /root

This command would transfer all files with the .txt extension in the /home/edward directory from the local machine to the remote machine’s /root directory.

Keep in mind, that to download and upload the files you need type the command put or get and to press the TAB key.

The commands you can run in the sftp> console are very similar to the normal Linux commands.

Wrap Up

ls, cd, pwd, mkdir all work in a similar manner in which they work on the Linux shell.

You can use lls and lpwd to list the local machine’s files and the local machine’s working directory. While ls and pwd is used to see files and the working directory of the remote server.

That’s it! You know all the sftp basics! Wasn’t that hard, was it! We hope this tutorial helped you out. See you in the next one.

About the author

Edward S.

Edward is Hostinger's copywriter. He's an expert communicator with years of experience in IT as a writer, marketer, and Linux enthusiast. IT is a core pillar of his life, personal and professional. Edward's goal is to encourage millions to achieve an impactful online presence. He also really loves dogs, guitars, and everything related to space.

Add Comment

Click here to post a comment

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

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in Glossary
What Are WordPress Private Pages and Posts?

Close