I am using the following script to loop through all files in a local folder and upload them to an
sshpass -p 'MY_PASSWORD' sftp -o StrictHostKeyChecking=no -o HostKeyAlgorithms=+ssh-dss MY_USERNAME@FTP_URL:/Import
for f in $FILES
chmod +X $f
If you want to generate the
put commands for
sftp as input, you'll have to pipe them. You can't process loops within a here-document. Also, you shouldn't use
sshpass -p, as the program's command line is visible to all processes on the system via
ps, even those of other users. (very briefly, but visible anyway.) Environment variables are only visible to the same user, though in general, ssh keys might still be preferable.
Something like this might work:
#!/bin/bash export SSHPASS=MY_PASSWORD for f in /path/* ; do echo put "$f" done | sshpass -e sftp user@whereever:/path unset SSHPASS
Any commands inside the loop are executed locally, anything you want to pass to
sftp as commands should be printed via
echo or such.
(Of course, the commands shouldn't print anything that's not supposed to go to