SFTP Commands Linux – Transfer Files Between Hosts (Cheat Sheet)

SFTP Commands Linux – Transfer Files Between Hosts (Cheat Sheet). In this post, we will discuss the Secure File Transfer Protocol (SFTP) in detail, its features and show you how to use SFTP commands to transfer files between hosts.

In Information Technology, protocols are used to exchange data between businesses. They allow the different connected devices to communicate with each other, regardless of their location, structure, or design. Every time you use the power of the Internet, you use network protocols to communicate and establish a connection.

In fact, with the advancement in technology, many people and businesses have switched to cloud services and use protocols to exchange data over the network. Apart from being a good achievement, it is also a subject of concern. Why?

Because the more businesses use protocols to exchange data, the chances of data exposure to unauthorized parties are high. Cybercriminals use various methods like hacking to steal data over the Internet. Hence, to deliver or exchange data using a secure way, most companies are using the Secure File Transfer Protocol (SFTP).

With Secure File Transfer Protocol it is a more secure mode to transfer files and offers complete flexibility and control over the files.

Let’s start this article blog about SFTP Commands Linux – Transfer Files Between Hosts (Cheat Sheet).

What is Secure File Transfer Protocol (SFTP)?

So firstly a Secure File Transfer Protocol (SFTP) is a network protocol that uses Secure Shell (SSH) security components to deliver a high level of security when transferring files from and to the system. It allows the use of different encryptions, SSH keys, user IDs and passwords, or a combination of both to fulfil the authentication of a connection.

With the help of the Secure File Transfer Protocol (SFTP), one can transfer files on both the local and remote systems more securely. There are many reasons to choose the Secure File Transfer Protocol (SFTP) over other protocols, such as it offers a high level of security and data protection against unauthorized parties.

Companies can also trigger or turn off the SFTP’s encryption system as per their need and choice. Another feature that makes SFTP a top choice is it offers complete flexibility and control over the files. Hence, the chances of data exposure to unauthorized parties are less with SFTP server.

If you are looking for a protocol that offers secure server to server file transfers, it is best to choose SFTP as it is more secure than other protocols, including FTP. Secondly SFTP protocol works over the SSH keys and creates a secure connection when moving data to the server. Also ensures that all files are encrypted and cannot be read by unauthorized users during the process or operation.

What are the SFTP Features?

Some of the major features of SFTP protocol is shown below:

  • Triple DES and AES algorithm Implementation for encryption.
  • Screen session.
  • Supports both IPV4 and IPV6 HTTP protocol.
  • Secure Transmission.
  • Username/password authentication.
  • TMUX support.

How Does SFTP Work?

Well The Secure File Transfer Protocol (SFTP) works in a client server architecture and prevents fraudsters from connecting to the server. Mostly the data is present on the server, and the client can access it by sending it a request, regardless of their location.

As a user selects and clicks a file, a request via the network is forwarded to the server for verification. The server then sends the requested data to the client in an encrypted format. It uses SSH keys and implements Triple DES and AES algorithms to encrypt the data and transfer files securely.

You can also authenticate data using a username and password or a public key on connecting to an SFTP server. The server matches the received public key and requests the user to enter the password and other details to complete the authentication.

After authentication, the data cannot be easily accessed by any unauthorized users. The different encryption and authentication methods ensure
that the data remains safe at all times, during transit or at rest.

Additionally, SFTP is available for all platforms and supports various advanced features that result in uninterrupted file transfers.

SFTP Commands Linux

Here is the list of all SFTP commands Linux that helps you to transfer files between hosts in Linux.

Connect SFTP Server

Importantly SFTP uses an SSH protocol to connect to the SFTP server. To connect to the remote SFTP server, you will require the SFTP server IP, username and password.

The basic syntax to connect to the remote SFTP server is shown below:

				
					sftp username@sftp-ip-address
				
			

For example, if you want to connect to the SFTP server hosted on IP 192.168.0.100, run the following command:

				
					sftp root@192.168.0.100
				
			

You will be prompt to enter the root password of the SFTP server. Once you are connected to the SFTP server, you will get the following shell:

				
					Connecting to 192.168.0.100...
root@192.168.0.100's password:
sftp>
				
			

Getting SFTP Commands Linux Help

Additionally SFTP provides a lot of commands, and all commands are difficult to remember. In this case, you can run the following command in the SFTP shell to list all SFTP commands:

				
					sftp> help
				
			

You will get a list of all commands in the following output:

				
					Available commands:
bye Quit sftp
cd path Change remote directory to 'path'
chgrp grp path Change group of file 'path' to 'grp'
chmod mode path Change permissions of file 'path' to 'mode'
chown own path Change owner of file 'path' to 'own'
df [-hi] [path] Display statistics for current directory or
filesystem containing 'path'
exit Quit sftp
get [-afPpRr] remote [local] Download file
reget [-fPpRr] remote [local] Resume download file
reput [-fPpRr] [local] remote Resume upload file
help Display this help text
lcd path Change local directory to 'path'
lls [ls-options [path]] Display local directory listing
lmkdir path Create local directory
ln [-s] oldpath newpath Link remote file (-s for symlink)
lpwd Print local working directory
ls [-1afhlnrSt] [path] Display remote directory listing
lumask umask Set local umask to 'umask'
mkdir path Create remote directory
progress Toggle display of progress meter
put [-afPpRr] local [remote] Upload file
pwd Display remote working directory
quit Quit sftp
rename oldpath newpath Rename remote file
rm path Delete remote file
rmdir path Remove remote directory
symlink oldpath newpath Symlink remote file
version Show SFTP version
!command Execute 'command' in local shell
! Escape to local shell
? Synonym for help

				
			

Verify Local and Remote Working Directory

You can use the lpwd command to check the working directory in your local system.

				
					sftp> lpwd
				
			

You should see your current working local directory in the following output:

				
					Local working directory: /home/vyom/Project/
				
			

Use the pwd command to check the working directory in the remote SFTP server:

				
					sftp> pwd
				
			

You should see your current remote directory in the following output:

				
					Remote working directory: /root/
				
			

List Files on Local and Remote System

To list all files and directories on the remote SFTP server, run the ls command:

				
					sftp> ls
				
			

To list all files and directories on the local system, run the lls command:

				
					sftp> lls
				
			

Upload a File to SFTP Server

To upload a single file named file1.txt to the remote SFTP server, run the put command:

				
					sftp> put file1.txt
				
			

To upload multiple files named file1.txt and file2.txt to the remote SFTP server, run the following command:

				
					sftp> put file1.txt file2.txt
				
			

Download a File From Remote SFTP Server to a Local System

Moreover SFTP allows you to download a file from any remote SFTP server to the local system using the SSH protocol. To download a single file named remote1.txt from the SFTP server to a local system, use the get command:

				
					sftp> get remote1.txt
				
			

To download multiple files named remote1.txt and remote2.txt from the SFTP server to a local system, use the mget command:

				
					sftp> mget *.txt
				
			

Navigating Directories in SFTP

To switch the directory from one directory to another on the remote SFTP server, run the cd command:

				
					sftp> cd /opt
				
			

To switch the directory from one directory to another on the local system, run the lcd command:

				
					sftp> lcd /home
				
			

Create and Delete Directories in SFTP

In order to create a new directory on the remote SFTP server, run the mkdir command:

				
					sftp> mkdir remote
				
			

Create a new directory on the local system, run the lmkdir command:

				
					sftp> lmkdir local
				
			

Remove a file on the remote SFTP server, run the rm command:

				
					sftp> rm remotefile1.txt
				
			

And to remove an empty directory on the remote SFTP server, run the rmdir command:

				
					sftp> rmdir remote
				
			

Exit from the SFTP Session

You can use run the exit command to exit from the SFTP session:

				
					sftp> exit
				
			

You can also use the following command to exit from the SFTP environment:

				
					sftp> !
				
			

That is it! Thank you for reading SFTP Commands Linux – Transfer Files Between Hosts (Cheat Sheet).

SFTP Commands Linux - Transfer Files Between Hosts (Cheat Sheet)Conclusion

In this SFTP commands linux – transfer files between hosts (cheat sheet) post, we explained about SFTP and all SFTP commands with some practical examples. I hope this will helps you to transfer files between hosts.

Finally Secure File Transfer Protocol is a secure mode of transmission used by businesses to prevent data from hacking or stealing. The protocol allows the use of SSH keys and other encryption methods to create a secure channel for transferring files from one system to the other. With the help of SFTP, businesses can establish a secure connection between hosts, servers, or systems. It works in a client server architecture and ensures that the data cannot be easily accessed by any unauthorized users.

Don’t forget to check more of our SFTP content here.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x