Recursive delete with the command line windows FTP client

If you’re dead set on finding a way to do a recursive delete with Windows’ standard command line FTP client you’re in the wrong place. Actually, the whole internet is the wrong place for you. Why? It’s simply impossible to find a way to do recursive deleting of directories in ftp.exe on the Internet. Well, I’ve searched high and low and couldn’t find it that is. If you can, I’d love to hear from you.

What I did find however is a way to achieve the same thing with a simple different FTP client.

At my job someone was looking for a way to delete all contents from a certain directory. This directory contains files and more directories (which in turn can contain more files and even more directories). This is easy if you’re working in a graphical FTP client like FileZilla but in our case it had to be done with a script. This meant we needed to work from the command line. Windows’ standard FTP client simply didn’t work. As long as a directory is not empty, it can’t be deleted. There are probably complicated scripts that can be written to do what we want but we’re no guru’s and we couldn’t find them by means of Google.

After a lot of searching we finally found our answer. I knew that the linux based FTP client LFTP does what we want with a built in command. All I had to was find a way to run it in Windows. Finally Google was my friend again. It didn’t take too long for me to find a windows version of LFTP. It’s in a ZIP file and it can be downloaded from here.

When running the included install.bat, Windows complained a little but that didn´t stop the program from working. I did need to specify the full path to the exe (for instance C:Windowslftp.exe) in order to run it. Now you could write a script like this:

debug 10
user <user> <pass>
rm -r <directory>

And after saving the script you can start LFTP like so:

C:Windowslftp.exe -f <script_file>

I assume you’ll understand that you’ll need to replace all text that is enclosed <like this> with their corresponding values (so replace <user> with the username to connect with and <pass> with the user’s password)?

For more info on using LFTP try the documentation or this page (with scripting examples).

Please let me know in the comments if you’ve found other ways to achieve the same thing (perhaps with Windows’ standard FTP client?). Hope this helps!

6 thoughts on “Recursive delete with the command line windows FTP client

  1. Be sure to run:
    set ftp:list-options “-a”

    Or else files beginning with “.” will not be processed, and nor will you be able to delete folders containing those files.

  2. Unless you’re adamant in trying to do this with a script for any reason, there are quite a number of pretty good GUI-based ftp utilities out there that can do this like you were deleting or moving files from your GUI desktop.

    You sure the internet is the right place for you? 😉

    1. Pretty sure, yes 🙂

      The objective here is to be able to use it in a script. So that you can, for instance schedule a cleaning type job.

Leave a Reply

Your email address will not be published. Required fields are marked *