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 ?
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:
Login to site.
Get a directory listing.
For each file in the listing, perform a "stat" command, getting filesize and timestamp.
Sort file listing by time, separate into two groups (your last 6 and all others).