Why doesn’t mget and mdelete play nice together?

One of my colleagues needed a shell script which should:

  1. connect to an external system via FTP
  2. change to a remote directory
  3. get all the files in the directory to local machine
  4. 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:
do_ftp()
{
rm -f $FPTLOG
ftp -n -v <remote_host> <<FTP >$FTPLOG 2>&1
user <user> <password>
cd  $REMOTE_DIR
lcd $LOCAL_DIR
mget *.txt
mdelete *.txt
bye
FTP
}

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!).

mget ZCNT_RECON_FBL1N_*.txt
ls         #Needed this for mdelete to work
mdelete ZCNT_RECON_FBL1N_*.txt

Geeks, any explanation on why this happens?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s