Shell script for FTP folder pattern

Hello,

I have 3 folders on FTP server in the format yyyymmddhhmiss as below,

ftp> cd /home/walgreens
250 CWD command successful

ftp> ls
200 PORT command successful
150 Opening ASCII mode data connection for file list
20150708072901
20150708092901
20150708102901

The above folders are in the format on FTP is YYYYMMDDHHMiSS .

ftp> dir
200 PORT command successful
150 Opening ASCII mode data connection for file list
drwxrwxr-x   2 root     root         4096 Jul  8 07:53 20150708072901
drwxrwxr-x   2 root     root         4096 Jul  8 09:53 20150708092901
drwxrwxr-x   2 root     root         4096 Jul  8 10:53 20150708102901
226 Transfer complete

The script needs to select the FTP folder 20150708102901 , since this is the latest one (arrived at 10am).

The script has to select the folder 20150708102901 and fetch the gz file inside it.

ftp> cd 20150708102901
250 CWD command successful

ftp> get CA.gz

Thanks
pavan

You may need to do this in three steps:-

  • Use ftp to get a listing
  • Work on the output to determine what to get
  • Use 2nd ftp to get it

Can you work out the steps that a human operator would do it? If so, then with refinement you can achieve your aim.

What have you tried so far, and where do you get stuck?

Robin