FTP vs SFTP vs SCP vs SSH: Which One to Use?
Have you ever wondered how to connect to a remote host? This article is going to introduce some of the commands that you may need when connecting to a remote machine! FTP, SCP, and SSH are network protocols for different purposes.
FTP/SFTP
File Transfer Protocol (FTP) is a protocol used to transfer files between a server and a client. SSH File Transfer Protocol (SFTP) is a newer protocol that does the same thing but uses a more secure connection. Therefore, it is better to use SFTP than FTP whenever possible.
To connect to a remote server using SFTP:
sftp username@server
After entering the password, you will be connected to the remote server. You can then use commands like GET or PUT to transfer files to or from the server. For more details, you can type help to view the manual.
SCP
Secure Copy Protocol (SCP) allows you to copy files between a server and a client or even between two servers.
To copy a file from a client to a server:
scp hello.txt username@server:/home
To copy a file from a server to a client:
scp username@server:hello.txt /home
To copy a file from one server to another:
scp username@server1:hello.txt username@server2:/home
It is not hard to remember how this command works because it works just like the cp command:
cp source destination
scp local_file server:directory # copy file from local to server
scp server:file directory # copy file from server to local
SSH
Secure Shell Protocol (SSH) allows you to connect to a remote server and execute almost any commands, not just transfer files. To access the remote server:
ssh username@server
After logging in, you can do almost anything to interact with the server.
Conclusion
The three protocols mentioned above are some of the most commonly used for accessing a remote server. There are many other network commands and protocols in use. If you are interested in learning how networks work, you should definitely explore them, such as rsync and SMB. Another useful tool for file transfer is cURL, a command line tool for sending or receiving files that supports numerous protocols.