Auto Script to Access external Server via SFTP using Password and Key

Hello All,

I am stuck!

I have access to an external server via SFTP. In order to access the external server I was given a specific port, password, and a ppk.

I would to create a script on my server end that can I can setup as a corn job, that will connect to the external server and download what ever is in the folder.

Thus far I was able to have a bash script that will automate the log-in process but not include the download of the files.

Any help you can provide would be nice. If you can provide an example script or reference links.

Thanks a lot in Advance.

You can create a control file to connect and run the SFTP commands.

Something like below:-

cat > sftp_control.cntrl
cd <destination path>
get <file name>

Then run it by passing it to SFTP:-

sftp -b sftp_control.cntrl user@host

You can use your script to create the commands in the control file.