• I did something almost identical several years ago (over FTP, not SFTP) using batch files to do an mget and then delete them. The problem I saw was that the FTP folder could potentially have a file posted to it after I fire the mget and before I deleted them. Besides, I wanted to be certain that the files arrived intact, so I used a slightly different approach.

    I first connected and did my mget. I then disconnected from the FTP server. Now the files are on a hard drive on the server, so I fired the following to dynamically create an FTP script file. The %ftpfile% variable contains the value script.ftp and is the name of the file. The %dirMailbox% variable contains the directory on disk where the files live and the files I received are the only files in that directory when this script runs.

    if exist %ftpfile% del %ftpfile%

    echo username > %ftpfile%

    echo password >> %ftpfile%

    echo cd /prod/outbox >> %ftpfile%

    echo prompt n >> %ftpfile%

    for /f "tokens=*" %%G in ('dir %dirMailbox% /b /a-d') do (

    echo rm %%G >> %ftpfile%))

    echo quit >> %ftpfile%

    start /wait ftp -v -s:%ftpfile% http://ftp.servername.com >> %logfile%

    type nul > %ftpfile%

    The result is that you write the rm command for each file you've received. For testing, you can rem out the last two lines to look at the resulting script.ftp file. Is this what you're looking for?