How to use sftp to upload or download files and folders in Linux
SFTP (Secure file transfer program) is a secure, interactive file transfer program that works in a similar way to FTP (File Transfer Protocol). However, SFTP is more secure than FTP, and it handles all operations by encrypting the SSH transport. In this article, we'll show you how to use SFTP to upload/download an entire directory (including its subdirectories and sub-files).
-
Aaron Kili Source: Linux China |2017-03-09 14:42
-
Mobile collection Sharing
51CTO invites you September 23 and second clap/gome/US group of experts to talk about the optimization of Intelligent CDN Road, seize the time Oh!
SFTP (Secure file transfer program) is a secure, interactive file transfer program that works in a similar way to FTP (File Transfer Protocol). However, SFTP is more secure than FTP, and it handles all operations by encrypting the SSH transport.
It can be configured to use several useful SSH features, such as public key authentication and compression. It connects and logs on to the specified remote machine and switches to interactive command mode, in which the user can execute various commands.
In this article, we'll show you how to use SFTP to upload/download an entire directory (including its subdirectories and sub-files).
How to transfer files/folders using SFTP in Linux
By default, the SFTP protocol establishes a secure connection to a remote server in the same way as the SSH transport protocol. Although user authentication uses a password method similar to the SSH default setting, it is recommended to create and use SSH without password login to simplify and more securely connect to the remote host.
To connect to a remote SFTP server, establish a secure SSH connection and create an SFTP session as follows:
- $ SFTP [email protected]
After you log on to the remote host, you can run the Interactive SFTP command as follows:
- sftp> LS #list directory
- sftp> pwd #print working directory on remote host
- Sftp> lpwd #print working directory on Local host
- sftp> mkdir Uploads #Create a new directory
Run SFTP Commands on Remote Linux
- Running the SFTP command on a Linux host *
How to upload a folder using SFTP
To upload the entire directory to a remote Linux host, use the put command. However, if the directory name does not exist in the working directory on the remote host, you will receive an error, as shown in the following screen.
Therefore, first create a directory with the same name on the remote host and upload it from the local host, and the-r parameter allows copying subdirectories and sub-files:
- Sftp> Put-r Tecmint.com-articles
- sftp> mkdir Tecmint.com-articles
- Sftp> Put-r Tecmint.com-articles
Uploading folders using SFTP
To preserve the modification time, access time, and mode of the files being transferred, use the-P flag.
- Sftp> PUT-PR Tecmint.com-articles
How to use SFTP to download folders
To download the entire fstools-0.0 folder from a remote Linux host to this computer, use the GET command with the-R flag as follows:
- Sftp> Get-r fstools-0.0
Download the catalog using SFTP
If the folder has already been downloaded, then look at the working directory of the Machine.
To exit the SFTP shell, enter:
- Sftp> bye
- Or
- Sftp> exit
Also, read this SFTP command and usage tips.
Note that in order to prevent users from accessing the entire file system on a remote host, for security reasons, you can use chroot Jail to restrict SFTP users to their home directory.
That's it! In this article, we show you how to upload/download an entire directory using SFTP. Use the comments section below to provide us with your views on this article/topic.
Author Profile:
Aaron Kili is a Linux and f.o.s.s enthusiast, a future Linux system Administrator and Web Developer, currently a tecmint content creator who likes to work with computers and believes in sharing knowledge.
How to use sftp to upload or download files and folders in Linux