This tutorial is aimed to show you how to download files from a remote sftp
server and of course how to upload files to a remote sftp
server. It’s useful if you are writing a bash or shell script which requires non-interactive usage of the SFTP command, and it’s very helpful for setting up cron jobs and automating the SFTP transferring files actions.
Prerequisites
- SFTP
Upload files from your machine to a remote SFTP server
Step 1. The default syntax for uploading files:
sftp (user)@(host):(remote_dir) <<< $'put (local_file_path)'
Step 2. Let’s say you want to upload multiple .csv
files from your machine to a remote SFTP server which requires user and password provided non-interactively:
sshpass -p "user_password" sftp [email protected]:remote_dir <<< $'put *.csv'
Download files from your machine to a remote SFTP server
Step 1. The default syntax for downloading files:
sftp (user)@(host):(remoteFileName) (localFileName)
Step 2. So if you want to download multiple .csv
files from a remote server to your local machine which requires user and password provided non-interactively:
sshpass -p "user_password" sftp [email protected]:remote_dir/*.csv local_dir/
Conclusion
As I mentioned these commands are useful for setting up a cron job for automating your SFTP transferring files. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.