March 20, 2019
March 20, 2019
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.
Let’s learn the basic sftp uses:
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 184.108.40.206 via SFTP we would use the command:
After this command, you are connected successfully to the remote server.
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:
To copy the /etc/xinetd.conf file from the remote server (220.127.116.11) to your local machine you would use the command:
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.
After the download, you can find all *.conf files in /user/home directory of your local machine.
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:
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.
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.