The Secure File Transfer Protocol (SFTP) is a network-based secure and encrypted mechanism for transferring data from a local computer to a distant server. It offers a secure substitute for conventional FTP, making sure that private information is kept secure while transferring files. SFTP has gained popularity as a secure file exchange method for both enterprises and individuals due to its broad adoption and strong security features. To securely transfer files over a network go for VSFTPD as it’s a secure FTP server and also learn how to install an FTP server on Ubuntu.
Secure file transfers are crucial in the modern digital environment to safeguard sensitive information from unauthorized access and security breaches. SFTP (Secure File Transfer Protocol) is one such dependable and durable mechanism for securely exchanging files between a local machine and a remote server.
SFTP offers a safe channel for information exchange by both guaranteeing data integrity and encrypting the data in transit. In this manual, we’ll go over how to safely transfer files using SFTP step-by-step, giving readers the knowledge they need to protect their data when transferring files.
How to Set Up SFTP Connection
By default, SFTP establishes a secure connection and performs authentication using the SSH protocol. As a result, SSH-compatible authentication techniques are also available. Although passwords can be used to authenticate by default, we advise creating SSH keys and sending your public key to any systems you need to access.
This is a lot more time-efficient and secure option. SFTP uses the SSH network protocol to create secure connections between systems. As long as a system has a copy of your public SSH key, you can connect to it using this method.
sftp [username]@[remote hostname or IP address]
In the example below, we are using the dedicatedcore username to access a device with the IP address 192.168.100.5:
sftp dedicatedcore@192.168.100.5
If you want to end the present connection, As below:
exit
How to Send Files Through SFTP
You can move files from a distant server to a local system using SFTP and vice versa.
1. Send Files from a Remote Computer to a Local One
In order to transfer a file from a distant server to your local system, use the get command in the SFTP interface:
get [path to file]
Use these steps, for instance, to move a file named example_document.txt from the Home directory of the distant system to the local one:
get example_document.txt
SFTP transmits files by default to the Home directory on the local machine. Put the directory’s path at the end of the get command to move files to a different location:
get example_document.txt Downloads
Add the new file name to the end of the get command to modify the filename on the local system.
get example_document.txt sample01.txt
In the aforementioned illustration, the get command downloads the example_document.txt file and saves it locally as sample01.txt.
By specifying a recursive transfer of all files in the directory with the -r flag, SFTP also enables the transfer of a whole directory from the remote system:
get -r Example_Directory
To transfer the file or directory while maintaining permissions and access times, add the -P parameter to the get command:
get -Pr Example_Directory
To confirm the transfer to the local system, run the ls command:
ls -l
2. Moving Local Files to a Remote Server
Use the put command to move files from a local system to a distant server. The syntax and available arguments for the put command are identical to those for forget.
put [path to file]
Use this example to send the file example01.txt to the distant server:
put example01.txt
Add the path to the directory to the end of the put command to move the file to a specific location on the remote server.
put example01.txt Example_Directory
The name of the transferred file on the remote computer is altered by appending a new filename to the end of the put command.
put example01.txt text_sample.txt
The -r parameter is required to move a whole directory.
put -r Test_Directory
For the put command to maintain file permissions, add the -P flag:
put -Pr Test_Directory
Using the ls command on the remote system, confirm the file transfer:
Maintaining files via SFTP
To modify the permissions of files and directories on a remote system, for example, you can use SFTP.
In a similar manner to chmod, the chown command changes the ownership of a file:
chown [user ID] [path to file]
The chown command accepts only user IDs, not usernames, unlike the chmod command.
get /etc/passwd
!less passwd
Each user’s UID can be found in the third column, separated by colons:
In the standard shell, the chmod command works the same way:
chmod [permission] [path to file]
The chgrp command can also be used to change group file ownership:
chgrp [group ID] [path to file]
In the Remote Server, the group IDs also get into the third column of the /etc/group file as such with the UIDs
get /etc/group
!less group
In Local system files which are moved changes default file approval that the SFTP allows you to set local umask
For instance:
lumask 022
The aforementioned command modifies the local umask to 022. Following the setting of this umask, the 644 permission is now the default for all transmitted files. By using the -p switch, the original permission can still be preserved. Using SFTP to mimic the actions of shell commands is another technique to modify local file permissions. To accomplish this, precede the command name with an exclamation mark (!).
Using the local system’s chmod command, for instance
!chmod [permission] [path to file]
Wrapping With How to Use SFTP to Transfer Files
Using secure file transfer protocols like SFTP is essential for protecting sensitive data as data security. That becomes a major priority in today’s connected society. We have shown how easy it is to use SFTP to create a secure connection between a local machine and a distant server throughout this article. Users can reliably transfer files without risking data integrity or falling prey to potential security concerns by putting the best practices recommended here into effect.
Remember that having a secure password, upgrading software often. Following security recommendations will help to protect your data during SFTP file transfers. Accept SFTP as a trustworthy and secure means for file transfers, and take aggressive steps to safeguard your digital assets. Hope this helped you with how to use SFTP to transfer Files.