How to Use SFTP for Secure File Transfer on VPS
To upload and download website files, you must be familiar with the File Transfer Protocol (FTP). FTP is a protocol for downloading and uploading files between client and server. However, the file transfer process using FTP is not safe enough. Instead, you can use a more reliable transfer protocol, namely SFTP.
SFTP stands for SSH File Transfer Protocol or Secure File Transfer Protocol. This tool is a separate protocol system from FTP but works in the same way. The difference is that transferring files using SFTP is safer because it is done through the SSH command line.
In this guide, we will explain a tutorial on how to use SFTP on VPS via the command line.
How to Use SFTP on VPS to Transfer Files Safely
The following is a guide on how to use SFTP remote server on VPS.
1. How to connect to SFTP
First, make sure you are connected to SFTP. If not connected to SFTP, enter the following command into the command line to log in using SFTP.
sftp root@IP_Server_Anda_atau_HostName
When running the above command, you will be asked to enter a password from your user or hostname.
The above command will connect you to the remote system, and your prompt will change to an SFTP prompt, as shown below.
To exit the SFTP prompt, you can use the following command:
exit
2. Learn the Basic SFTP Commands
If you are a new SFTP user, no need to worry. Because SFTP provides a help feature to find the basic commands in SFTP, to see basic commands in SFTP, use the help command or? The output will be as shown below.
When logging into the remote server, the default directory used is the home directory. To check this, you can use the following command:
pwd
The output will be like in the image below. This means you are in the homework directory.
To see a list of files in the home directory, you can use the following command:
ls
You can also move to other directories. For example, below we move from the root directory to the, etc. directory:
cd /etc
You can adjust the command above with your directory. To determine the location of the directory, check using the PWD command to your command line.
Also Check: MX Record: Definition, Function & How to Set up
4. Transfer Files With SFTP
With SFTP, you can also transfer files securely. The following is how to transfer data using SFTP.
Download Files with SFTP Commands
To download files using SFTP, make sure you are in the location where the file directory is stored. To download a file from a remote server, use the following command:
get namafile.zip
The output will be as below:
Fetching /home/remote_username/namafile.zip to namafile.zip
/home/nama_remote/namafile.zip 90% 28MB 1.8MB/s 00:14
If you want to save the downloaded file using a different name, you can use the new name as the second argument in the command like the following example:
get namafile.zip namafilebeda.zip
The command described above is as follows:
filename.zip is the file that will be downloaded, and filename.zip is the result of downloading the file.
Upload Files with SFTP Commands
Before uploading a file from a computer, make sure you are in the file directory to be uploaded. Then you can use the following command to start uploading files from a computer:
put namafile.zip
The output will be as below:
Uploading filename.zip to /home/remote_username/namafile.zip
namafile.zip 90% 15MB 1.8MB/s 00:07
If when the file upload process to the server directory fails, you can repeat it using the following command:
reput namafile.zip
5. Learn the Basic SFTP Commands
The following are some basic commands that are often used when using SFTP for remote servers.
Check Disk Information
You can check disk or storage information on your server using the following command:
df
Create a Directory
To create a directory on a remote server, you can use the following command:
mkdir nama_direktori
Rename File
To change the file name on the remote server, enter the command below:
rename nama_file_lama nama_file_baru
Delete File
To delete files on the remote server, you can use the following command:
rm nama_file
Change File Permissions
You can also change file permissions when using a remote server. The way is to use the chmod command. Here are the complete instructions:
chmod 644 nama_file
Change File Owner
To change the permissions of the file owner on the remote server, use the following command:
chown user_id nama_file
Change File Group Owner
You can change the owner of the group file using the following command:
chgrp group_id nama_file
Conclusion
In this tutorial, you have learned how to use the sftp command to download and upload files to a remote SFTP Server.
Hopefully our article can help you to transfer files safely using SFTP. Thus the article about how to use SFTP to transfer files securely. If you still have questions do not hesitate to leave in the comments column. Don’t forget to follow us on social media to stay updated.
Also Check: What is Comodo SSL? Learn Types and Functions?