premal has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I want to write a script to delete a folder from FTP server. We have all the folders are named in yyyy_mm_dd (which indicates present year month and date)format under FTP server. I will use Net::FTP to connect to FTP server but I would like to know the logic of what should i do if i want one folder having the oldest date in its name should get deleted after the new is uploaded.

Replies are listed 'Best First'.
Re: Deleting folder from FTP server
by FalseVinylShrub (Chaplain) on Dec 16, 2009 at 11:25 UTC

    Hi

    Well... this is what I would do:

    1. Connect to FTP server 2. Get a directory listing of the required location 3. Iterate through the list of directories and: 3.1. Disregard directories that don't match the date format 3.2. Keep record of the oldest directory (so far) 3.3. Count number of directories with date format name 4. Sanity checks (there's more than 1 valid directory, etc) 5. Delete the oldest directory found in the loop

    If that was what you were after... ?

    If you were wanting more specific code, perhaps post some code and say what doesn't work, or where you don't know what to do next.

    FalseVinylShrub

    Disclaimer: Please review and test code, and use at your own risk... If I answer a question, I would like to hear if and how you solved your problem.

      I will try to implement the steps you have suggested. Thanks for your help