Uploading Files by Wrapping sftp in a Shell Script
Overview
A third party providing a data analytics service instructed us
to store files on a specified server and path, in a specified format.
They also added:
“Please use sftp as the only allowed protocol.”
Since we also needed to run this on a schedule,
we looked into whether it could be written as a shell script,
and put together the following.
shell
Point
Using
expectto feed the password ahead of time to the sftp command, which is normally interactiveSpecifying
bachmode nowith the-ooption to avoid the following error
1 | Permission denied (publickey,password). |
- The
-boption lets you write the processing to run after the sftp login into a batch file
In our case, we needed to run the shell script on a schedule via Jenkins or cron,
so we made it possible to explicitly specify the contents of the batch file.
That’s all.
