Solved

Delete ftp files with a wildcard

Posted on 2011-09-19
12
2,646 Views
Last Modified: 2012-05-12
Hi,
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

20110915_FileName.txt

I am trying to do something like this.

open ftp.abcd.com
UserName
Password
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
close
bye

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
0
Comment
Question by:esotericmee
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 6

Expert Comment

by:tmwsiy
Comment Utility
* are only valid at the end of the string with mdelete.
0
 

Author Comment

by:esotericmee
Comment Utility
So then what would be needed to be done to achieve my goal?
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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_*.*

~bp
0
 
LVL 6

Expert Comment

by:tmwsiy
Comment Utility
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*

0
 

Author Comment

by:esotericmee
Comment Utility
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.
0
 
LVL 16

Expert Comment

by:AlexPace
Comment Utility
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:
:start
;; 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 "ftp.mydomain.com" /user="UserID" /pw="Secret"
FTPCD "/subfolder"
FTPDELETE MyWildcard
FTPLOGOFF

;; 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: http://kb.robo-ftp.com/script_library/show/45
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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.
0
 
LVL 16

Expert Comment

by:AlexPace
Comment Utility
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.
0
 
LVL 51

Expert Comment

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

del foo*.txt

~bp
0
 
LVL 51

Expert Comment

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

http://www.scriptftp.com/reference.php?go=topic170

~bp
0
 

Accepted Solution

by:
esotericmee earned 0 total points
Comment Utility
Hi,
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.,
0
 

Author Closing Comment

by:esotericmee
Comment Utility
The experts gave me a direction and I eventually found the way to get it done.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

762 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