One of my colleagues needed a shell script which should:
- connect to an external system via FTP
- change to a remote directory
- get all the files in the directory to local machine
- and delete all the files in the remote directory
The ftp commands mget and mdelete can be used to retrieve and delete multiple files respectively. And the code snippet would be:
rm -f $FPTLOG
ftp -n -v <remote_host> <<FTP >$FTPLOG 2>&1
user <user> <password>
This should do the job, right? Unfortunately it doesn’t. mget works, but the mdelete afterwards isn’t triggering at all when I checked vsftpd.log.
I managed to save the day by putting a harmless command in between (looks like they need a mediator!).
ls #Needed this for mdelete to work
Geeks, any explanation on why this happens?