-->

How to Use SFTP for Secure File Transfer on Linux

SFTP is SSH File Transfer Protocol. This works over ssh protocol for secure file transfer between two remote systems. The latest OpenSSH servers have default configured SFTP server for you.

Connect to SFTP

Use sftp command line utility to connect remote sftp system. You need the sftp user and hostname or IP address of the remote host.
 sftp user@remote.host

Navigate and View Files

Navigation in directories on SFTP is as simple as the local system. Use ‘pwd’ command to check the current working directory.
sftp> pwd

Remote working directory: /
Then use ‘ls’ command to list all files and directories in the current directory.
sftp> ls
To navigate to other directories use ‘cd’ command followed by destination directory.
sftp> cd uploads
Use ‘cd ..’ to navigate to the parent directory.
sftp> cd ..

Upload files to SFTP

Now, I need to upload some files under uploads directory. So first navigate to destination directory.
sftp> cd uploads
sftp> pwd
Remote working directory: /uploads
Use ‘put’ command to upload README.md from local system to remote sftp directory.
sftp> put README.md
You can also provide the absolute path of the local file and remote directory without navigating directories.
sftp> put /var/www/README.md /uploads/20181218/

Download Files from SFTP

To download files from remote sftp directory use ‘get’ command. For example to download REMOTE_FILE.md from remote system to the current local directory.
sftp> get REMOTE_FILE.md
Similarly, you can provide an absolute path to download files.
sftp> get /uploads/REMOTE_FILE.md /var/www/

Exit from SFTP

Simply say bye to your remote SFTP server. This will disconnect the SFTP connection and return to your local shell.
sftp> bye
Alternatively, you can also use one of the following options to quite from the SFTP session. These all 3 do the same work.
sftp> quit
sftp> exit 

No comments:

Post a Comment