I am porting some batch jobs from Window to Linux. These are .bat scripts on Windows and I am rewriting them in Python to run on Linux
On Windows, we currently use putty to SFTP files and run commands like this:
psftp user@host -i privatekey.ppk -batch -b script.txt
This executes the putty SFTP commands found in script.txt in batch. Example below:
SCRIPT.TXT example
cd mydir
lcd outbox
get myremotefile.txt mylocalfile.txt
get myotherremotefile.txt myotherlocalfile.txt
bye
I am trying to find a way to use the same batch script (script.txt) in my python script to minimise the amount of changes overall. I've been looking into paramiko but so far I have not been able to find a way to execute the sftp commands in bulk via a script file.
An alternative would be to spawn a sub-process to execute the sftp command with the -b option but would prefer a python native solution if possible.
What do you think? Are there other options out there to solve this?