Delete ftp files with a wildcard

Posted on 2011-09-19
Last Modified: 2012-05-12
I am trying to write a script to delete the files with a particular name on the FTP server. I dont want to delete all the files with *.txt extension. The file name would be like


I am trying to do something like this.

cd FolderName
mdelete *.txt --- here I want to pass a wild card to delete only files with a particular name and not all files with a .txt extension

This will be a unattended batch script scheduled to run everyday. I am not very familiar with the programming languages. Please provide a simple solution if possible. Thanks
Question by:esotericmee
  • 4
  • 3
  • 2
  • +2

Expert Comment

ID: 36563195
* are only valid at the end of the string with mdelete.

Author Comment

ID: 36563218
So then what would be needed to be done to achieve my goal?
LVL 52

Expert Comment

by:Bill Prew
ID: 36563229
If there are no files with extensions other than txt for the pattern you want, you might be able to do something like:

mdelete 20110915_*.*


Expert Comment

ID: 36563243
wait you say you want to delete all files EXCEPT the ones with .txt extenstion?

if so lets say the "name" you mention above is potato then it would be

mdelete potato*


Author Comment

ID: 36563284
There are files with extensions other than txt. I want to add the wild card of the filename

eg mdelete filename_*.txt

The pattern for the file is DATE_FileName.txt
 eg: 20110915_Myfile.txt

I want to add "Myfile" as the wildcard
The date part will change everyday and the rest of the filename would be the same.

There are other files with the extension of txt and with other extensions.

Thanks for the help. I appreciate it.
LVL 16

Expert Comment

ID: 36563569
You could do this with a Robo-FTP script configured to run as a Windows Service.  This way the operating system will automatically restart the job whever the computer reboots.

This example script will delete all the files named with your date-based wildcard pattern calculated using the date 3 days ago.  It is designed to execute immediately the first time you run it and then at 10pm every night after that:
;; Find the date 3 days ago
SET myDate = %date 
DATESUB yesterday 3      

;; Parse date as string with "-" character as delimiter
;; then rearrange the values to change the name pattern 
SETEXTRACT month = yesterday "-" 1
SETEXTRACT day = yesterday "-" 2
SETEXTRACT year = yesterday "-" 3
SET MyWildcard = "20" + year + month + day + "*.txt"

;; delete all files that match name wildcard pattern
FTPLOGON "" /user="UserID" /pw="Secret"
FTPCD "/subfolder"

;; wait until 10pm
PAUSE /until=22:00
GOTO start

Open in new window

Of course you'll need to modify the login information on line 14 and the name of the remote site's subfolder on line 15 but otherwise it should be good to go.  It is a modified version of this:
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

LVL 68

Expert Comment

ID: 36563682
The only way to reliably perform that via (standard) FTP is to get the directory listing, filter the files you want to delete, and generate delete commands for each file name.
LVL 16

Expert Comment

ID: 36563695
Qlemo is correct.  If you look at the protocol trace log this is exactly how the Robo-FTP script I posted above does it't work.
LVL 52

Expert Comment

by:Bill Prew
ID: 36564013
If you can connect via SFTP, then the open source PuTTY client includes PSFTP, and it does support delete commands like:

del foo*.txt

LVL 52

Expert Comment

by:Bill Prew
ID: 36564044
Like Robo-FTP, not free, but another FTP scripting tool that does support wildcard deletes.


Accepted Solution

esotericmee earned 0 total points
ID: 36588756
I just did
mdelete *pattern*.* and it delete all the files containing the "pattern"
I did not think it would be that straightforward.

Thanks experts for all your comments. I appreciate the help.,

Author Closing Comment

ID: 36715383
The experts gave me a direction and I eventually found the way to get it done.

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to roll into all sub dirs 7 44
Trasfering FSMO roles 8 95
move command 5 52
inplace upgrade from Windows 2003 R2 to 2012 8 46
I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now