Home Linux Use SFTP to Securely Transfer Files with a Remote Server

Use SFTP to Securely Transfer Files with a Remote Server [2021]

0
Advertisement

Since this is a technical post, I won’t be going in theory or briefing. I will come straight to the point. In this post, you will learn how to Use SFTP to Securely Transfer Files with a Remote Server.

Quick Glance:

FTP is known as File Transfer Protocol. FTP is the best and most popular unencrypted method used when you have to transfer files between remote systems.

Advertisement

What about SFTP, Well SFTP stands for SSH File Transfer Protocol. It’s also a secure file transfer protocol and does the same job. However, it’s packed with different packages, and the main difference between FTP and SFRP is just the SFTP uses a secure connection when it comes to transferring files.

There was a time when everyone used to go with FTP but since it was unencrypted, developers moved to SFTP. FTP does not provide a secure connection and there is no SSH connection in FTP Package.

How to Install PostgreSQL on Ubuntu

That’s why I am making this post and helping you learn how to use SFTP to Securely Transfer Files with a Remote Server. Let’s dive into it and start working.

How To Use SFTP to Securely Transfer Files with a Remote Server:

I have made a step-by-step guide in order to help you learn how you can connect with SFTP, get Help, Navigate, and much more.

How to Connect with SFTP:

Just to remind you that by default, SFTP uses the SSH Protocol when it comes to authenticating and establishing a secure connection.

Now if you have worked with the SSH, you will be glad to know that the same authentication methods will be used which are currently present in the SSH package.

You can use passwords but I would recommend SSH keys. They are more secure than passwords.

Now let’s move on and I will tell you how you can set up SSH keys. Use the following command to create an SSH key.

Create an SSH Key:

$ ssh-keygen

Connecting With SFTP:

Now that you have created your SSH key and you can easily connect to your machine. It’s time to test SSH access with the following command.

$ ssh sammy@your_server_ip_or_remote_hostname

If it’s working fine you need to exit now using the following command.

$ exit

Use the following command to establish a connection with SFTP.

$ sftp sammy@your_server_ip_or_remote_hostname

By default, SFTP uses the default Port (22). However, If you are using a custom port then use the following command.

$ sftp -oPort=custom_port sammy@your_server_ip_or_remote_hostname

This command will help you connect with the remote system and with your given port.

Getting Help in SFTP:

If you are looking the command to get help and also want to get a summary of help commands. Use the one below.

sftp> help

or

sftp> ?

After hitting enter you will get the following results.

SFTP to Securely Transfer Files

Navigating with SFTP:

We can use a number of commands in order to navigate through our remote system directories.

Let’s start with in which directory we are, use the following command.

sftp> pwd

If you want to view the content of the current directory. Use the following command.

sftp> ls

In order to get another directory, use the following command.

sftp> cd testDirectory

Now if you want to access the local file system on your remote system. Type-in the following command.

sftp> lpwd

List the content of the current directory.

sftp> lls

To change the directory on the local system.

sftp> lcd Desktop

Transferring Files with SFTP:

You can navigate through your remote system but it is of un us-use. Unless you start transferring file between the two.

Transferring Remote Files to the Local System:

To download the files from a remote system, type the following command.

sftp> get remoteFile

Upon hitting the enter button a remote file will be downloaded on your local system.

Copy the remote file to a different name.

sftp> get remoteFile localFile

Copy a directory and all of its contents.

sftp> get -r someDirectory

Transferring Local Files to the Remote System:

In order to transfer local file to the remote system. We will use (Put) flag instead of get.

sftp> put localFile

Copy an entire local directory.

sftp> put -r localDirectory

In order to check that you have enough space on your remote system or not. Use the following command.

sftp> df -h

Return to your SFTP session, type:

$ exit

Conclusion:

There you go, now you know the following.

  • Transferring Local Files to the Remote System.
  • Transferring Remote Files to the Local System:
  • Navigating with SFTP.
  • Getting Help in SFTP.
  • Connecting With SFTP.

That’s all.

Advertisement
David Is a Tech Geek, He Loves to Share his personal experiences on It'sDailyTech.

LEAVE A REPLY

Please enter your comment!
Please enter your name here