This post is about removing muliple files from the remote server, when sftp password less connection is setup. I have the code as below. Only first file in the variable $file_list
gets deleted, when I have the variable set as,
$file_list="file1 file2"
sftp $USER@$HOST
rm $file_list
quit
SFTP-Session
I even tried executing the commands in prompt mode.
sftp $USER@$HOST
rm file1 file2
However, I still see that only file1 is getting deleted.
I am not sure if I am missing any basic command.
I tried mdelete
/mdel
/mrm
, which were rejected as Invalid command in sftp prompt window.
Best Answer
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.
This one-liner is far better! file1-9 being file names to remove, use a variable if you like, it's the same thing.