Dear team , thanks for your support. I am trying to not to duplicate a thread if one is already there for what I am looking, which I am not able to figure out. Is it OK if I post the post the following question in new thread.
---
" I am having little trouble to create a script to get file from UNIX box to Windows through ftp. Right now I amusing the following script to pick specific file.
FTP open <remote server>
'login'
'pwd'
cd 'files path in remote server '
get 'DAILYFEED_20151202_163216.txt'
How to pick the latest one if there are many files with the similar name and time stamp is different in file name.
i would do it in 2 passes. first connect and issue an ls -l command. save the output to a file, then examine the file and decide which file(s) you want and re-connect to retrieve.d
ftp host >filelist
user
password
cd 'filepath'
ls
quit
You should now have a list of all the files on the source system, in the local file filelist.
You should now examine filelist to decide which file(s) you want to move and write them to a new file looking something like
cd pathtofile
get DAILYFEED_20160121.txt
quit
then re-connect
ftp host <new_file
If you are running the ftp client on the unix system, then you can create a .netrc file in the home directory of the user running these scripts so that you do not need to enter the user and password.
Sample script to select files:
count=0
echo "cd pathtofiles"
while read filename
do
if [ $filename = "some criteria" ]
then
echo get (or maybe put) $filename
count=`expr $count + 1`
fi
done <filelist
echo "quit"
if [ $count -eq 0 ]
then
exit 1
#no files selected
else
exit 0
fi