#! /bin/sh
#Do an ftp and get the list of filenames starting with ULT
ftp -ivn hostname <<INPUT >& out
user rakesh Welcome
ls ULT*
bye
INPUT
#Obtain the latest filename inside the variable filename using sort command
filename=`awk '{if($NF ~ "ULT") {print $NF}}' out | sort -r |
sed -ne '1p'`
#Do ftp again and get the desired file
ftp -ivn hostname <<INPUT >& out
user rakesh Welcome
get $filename