Search code examples
windowsbatch-fileftp

How to run FTP script from batch file on Windows?


I'm trying to create a .bat file to delete all XML files on a certain FTP folder regardless of the date of the file. I've tried many scripts without any solution.

Many experts are talking about .txt file containing the below script, but to be quite honest I don't know how to execute it or even am if I am creating the file correctly or not.

All I need is to delete all the files on this container.

open ftp://xxxx.xxxx.net
myusername
mypassword
cd /bts/xxxx
mdelete *
quit

Solution

  • Your FTP script looks ok. You just might want to replace mdelete * with mdelete *.xml, if there are also other files than .xml in the folder.

    To actually run the script, run ftp.exe from your batch file like:

    @echo off
    echo Running FTP to delete XML files...
    ftp -s:ftp.txt
    

    where ftp.txt is filename containing your FTP script (the one from your question).