How to remove multiple files using sftp
Here is one possible solution that can be added to bash script. This is not ideal as it will make a new connection for each file.
#!/bin/bash
# set variables
USER="username"
HOST="hostname"
file_list="file1 file1 file3 file4"
# delete each file
for file in $file_list; do
echo "rm $file" | sftp $USER@$HOST
done
exit 0
This one-liner is far better! file1-9 being file names to remove, use a variable if you like, it's the same thing.
for file in file1 file2 file3 file4 file5 file6 file7 file8 file9; do echo -e "rm $file" >> sftp_batch; done; sftp -b sftp_batch username@hostname; rm sftp_batch