delete old files from FTP server

Hi

I just started learning Unix scripts.

I need to access an FTP server, delete all the files except the latest 6 files and the latest 6 files should be downloaded to my local server. Could some body help me to code this logic in KSH ?

Thanks
Athena

Not really possible within KSH, afaik. If you explore Perl or Python, there are modules there to perform low-level FTP operations. Basically you would need to do something like this:

  1. Login to site.
  2. Get a directory listing.
  3. For each file in the listing, perform a "stat" command, getting filesize and timestamp.
  4. Sort file listing by time, separate into two groups (your last 6 and all others).
  5. For all but the newest 6 files, delete them.
  6. Download the 6.