

Note that to prevent users from accessing the whole file system on the remote host, for security reasons, you can restrict sFTP users to their home directories using chroot Jail. Then check in the current working directory on the local host, if the directory was downloaded with all the contents in it.Īdditionally, read through the sFTP commands and usage tips. To download a whole directory called fstools-0.0 from remote Linux host to local machine, use the get command with the -r flag as follows: sftp> get -r fstools-0.0 To preserve the modification times, access times, and modes from the original files transferred, use the -p flag. Therefore, first create a directory with the same name on the remote host, before uploading it from the local host, the -r does the magic, enabling subdirectories and subfile to be copied as well: sftp> put -r -articles

However, you will get an error if the directory name doesn’t exist in the working directory on the remote host as shown in the screenshot below. In order to upload a whole directory to a remote Linux host, use the put command. Run sFTP Commands on Remote Linux How to Upload a Directory Using sFTP Sftp> mkdir uploads #create a new directory Sftp> lpwd #print working directory on local host Sftp> pwd #print working directory on remote host Once you have logged into the remote host, you can run interactive sFTP commands as in the examples below: sftp> ls #list directory To connect to a remote sftp server, first establish an secure SSH connection and then create an SFTP session as shown. Although, passwords are used to authenticate users similar to the default SSH settings, but, it is recommended to create and use SSH passwordless login for simplified and more secure connection to remote hosts. How to Use sFTP to Transfer Files/Directories in Linuxīy default, SFTP adopts the same SSH transport for establishing a secure connection to a remote server. In this article, we will show you how to upload/download a whole directory (including it’s subdirectories and subfiles) using sFTP. It connects and logs into the specified remote machine, and switches to an interactive command mode where user can execute various commands. It can be configured to use several useful SSH features, such as public key authentication and compression. However, sFTP is more secure than FTP it handles all operations over an encrypted SSH transport. SFTP (secure File Transfer Program) is a secure and interactive file transfer program, which works in a similar way as FTP ( File Transfer Protocol).
