How to SFTP on a remote server

In this article, you will learn how to use SFTP for Secure Transfer Files via the command-line interface.

The SSH File Transfer Protocol is a network protocol that provides file access, file transfer, and file management over any reliable data stream. 

 

Requirements

 

First of all, make sure that you are able to connect your server through an SSH  connection.

You can verify the SSH connection by running the following command:

 

ssh username@Server’s_IP -p port

e.g: ssh root@185.184.69.72 -p 51821

 

Set UP SSH Keys

 

We recommend generating SSH keys and transferring your public key to the system you wish to access. If you wish to use SFTP by authenticating using passwords you may skip this section.

 

Generate SSH Keys

 

You can set up an RSA token by running the following command:

 

ssh-keygen -t rsa

 

Then, you will be asked a couple of questions such as the path file of your SSH key.

We recommend using the default settings by pressing Enter to all of the above steps.

 

Expected output:

However, if you wish for more enhanced security you may set a passphrase and every time you try to log in to a remote server, you will be asked for a password

 

Once the process is completed there will be two keys saved in the relative directory, one Private(id_rsa) and one Public(id_rsa.pub).

 

Copy SSH Keys to Remote Server

 

You can copy the public key file by running the following command:

 

ssh-copy-id -p port username@Server’s_IP

 

Use the username & IP address of the remote server you wish to copy the key.

 

Expected output:



Type yes in the command prompt and press ENter in order to continue.



Type the remote’s server’s password and press Enter.



Now you can log in to the remote server by running the following command:

 

ssh -p port username@Server’s_IP

 

Example output:



Connect through SFTP

 

Now, you may establish an SFTP connection by running the following command:

 

sftp -oPort=port username@Server’s_IP

 



To view a list of the available commands, type help command.

 

Navigate through SFTP

 

First of all, we need to check which directory we are currently connected to by running the following command:

 

pwd

 

For example, if wish to navigate to /testdir/ directory we will run the below command:

 

cd /testdir/


 In order to view the content of your selected folder you may run the following command:

 

ls -la


Expected output:


 

Transfer Files through SFTP

 

If you wish to download files from the remote host that you are currently connected to, type the following command:

 

get filename

 

Expected output:



The transfer of the file is now completed. Note that the file will be transferred with the same name.

In case you wish to transfer a file and simultaneously change the file name you must run the following command:

 

get filename newfilename

 

For downloading multiple files:

 

mget /testdir/*

For downloading a whole directory with its contents using the following command:

 

get -r directoryname  

 

 You can also download a  whole directory with its contents and maintain the relative permissions and access time by running the command:

 

get -Pr directoryname

 

If you wish to upload files from the local system to  the remote host that you are currently connected to, type the following command:

 

put filename

 

Note: If you encounter the error Permission Denied you should also check the file’s permissions that you are trying to upload.

 

Change file’s permission: chmod 755 filename

 

Change directory’s permission: chmod 644 directoryname

 

For transferring  a whole directory with its contents using the following command:

 

put -r directoryname

 

If you wish to temporarily go back to your local system you can type: !

For example, this command is useful if we need to check the available disk capacity of our local system by using the following command:

 

df -h

 

Then type exit in order to return to your previously SFTP connection:





Lastly, if you wish to exit the SFTP session type the bye command.




Connect through FTP client

 

For this section, we will use the FileZilla client.

 

Step1: Navigate to the File Tab and select Site Manager

 



Step2:  Select the New site option in order to create a new SFTP connection

 

 

Step3: Fill out your connection details as shown in the example below

 



Step 4: Press Connect option

 

Step 5: Press OK regarding the Unknown host key notification




Note: You may view also the status logs that will appear for possible errors.


 

Congratulations! You have successfully connected to your server via SFTP through Filezilla!



  • sftp, ftp, file transfter, linux, filezilla
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Disable OpenDNS resolver on Windows Server Operating Systems

An open DNS resolver is a DNS server that responds to recursive DNS queries from any IP address...

Disable OpenDNS resolver on Windows Server Operating Systems

An open DNS resolver is a DNS server that responds to recursive DNS queries from any IP address...

Disable OpenDNS resolver on Windows Server Operating Systems

An open DNS resolver is a DNS server that responds to recursive DNS queries from any IP address...

Enable GUI on Ubuntu Server (18.04/20.04)

In this article, we take a look at how to install GUI on Ubuntu server 18.04 and 20.04. Because...

Enable GUI on Ubuntu Server (18.04/20.04)

In this article, we take a look at how to install GUI on Ubuntu server 18.04 and 20.04. Because...