Hi Guys,
Am writing a FTP script to download file from a remote server.
There are 3 files in the target directory.
eg.
bfg234.2
vfg345.1
abc123.1
abc123.2
I need to get the file "abc123.2". The number could be increasing everytime.I need to get the latest file. can this be done ?
try
filename=$(
ftp <<-EOF | cut -c12-22 | sort | tail -1
open remoteserver
USER username
PASS password
dir abc*
EOF
)
The format of what gets returned will depend on the kind of ftp server. Not all ftp's behave precisely the same. e.g., mainframes, windows, and UNIX may have different formats.
So change
cut -c12-22
to get the filename out of the string. Experiment by changing the numbers.
Trailing spaces are ok.