How to use sftp to upload or download files and folders in Linux

Source: Internet
Author: User
Tags file transfer protocol

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:

    1. $ SFTP [email protected]

After you log on to the remote host, you can run the Interactive SFTP command as follows:

    1. sftp> LS #list directory
    2. sftp> pwd #print working directory on remote host
    3. Sftp> lpwd #print working directory on Local host
    4. 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:

    1. Sftp> Put-r Tecmint.com-articles
    2. sftp> mkdir Tecmint.com-articles
    3. 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.

    1. 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:

    1. 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:

    1. Sftp> bye
    2. Or
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.