March 5, 2020
March 5, 2020
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.
SFTP (SSH File Transfer Protocol), however, is a more secure way to transfer files. Using the SSH protocol, SFTP supports encryption and other security methods used to secure file transfers. 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 commands and what you can use them for.
The syntax for connecting to a remote server via SFTP on Linux distribution is:
sftp user@ip-address sftp email@example.com
If we want to connect to a Linux VPS servers with the IP 126.96.36.199 via SFTP we will use the command:
You will be prompted to enter your password, and now you are successfully connected to the remote server.
To begin, let’s check which local directory and which remote directory we are using. To do check, type in these commands:
sftp> lpwd Local directory: /printedhere
sftp> pwd Remote directory: /printedhere
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:
For example, to copy the file /etc/xinetd.conf from the remote server to your local machine, you would use the command:
After the download, you can now find that the file xinetd.conf is in the /user/home directory of your local machine.
To download multiple files, use the mget command. To download all files in a directory called /etc that have the .conf extension, you will use the following command:
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
To transfer the file example.txt from a local machine to the remote machine, enter the following command:
put /home/edward/example.txt /root
Now 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 will need to type the command put or get and press the TAB key.
There are many similar commands and functions, especially when looking at the Linux shell. Here are some standard SFTP commands that you can use.
cd – change the directory on the remote host
exit (quit) – close the connection to the remote host, and exit SFTP
get – copy a file from the remote host to the local computer
mget – copy multiple files from local to remote
put – copy a file from the local computer to the remote host
mput – copy multiple files from local to remote
rename – rename a file on the remote host
rm – delete a file on the remote host
help (?) – list of SFTP commands
version – display the SFTP version
pwd – show the present working directory on the remote host
lpwd – show the present working directory on the local computer
mkdir – create a directory on the remote host
ls– list the contents of the current directory on the remote host
lls – list the contents of the current directory on the local computer
chmod – change the permissions of the files on the remote host
chown – change the owner of the files on the remote host
That’s it! Now you know the SFTP basics. We hope this tutorial helped you out, and these commands will be beneficial for you. Good Luck!