Skip to content

Instantly share code, notes, and snippets.

@bmangesh
Last active August 29, 2015 14:08
Show Gist options
  • Save bmangesh/04de0cb1a5787e887f7b to your computer and use it in GitHub Desktop.
Save bmangesh/04de0cb1a5787e887f7b to your computer and use it in GitHub Desktop.
Fetch latest timestamp file from ftp server e.g abcdDDMMYY.txt
#!/bin/bash
#Author: MANGESHKUMAR B BHARSAKLE
#PROBLEM:How to download latest timestamp file from FTP remote SERVER to local
if [ -f tempfile ]
then
rm -rf tempfile
fi
ftp -n 192.168.127.151 >tempfile <<EOF
user ftp ftp
cd pub
ls -t
quit
EOF
var=`cat tempfile | head -1 | tr -s ":" | cut -d ":" -f2 | cut -d " " -f2`
echo "File Name $var"
ftp -n 192.168.127.151 <<EOF
user ftp ftp
cd pub
ls -t
get $var
quit
EOF
if [ -e $var ]
then
echo "File Found"
else
echo "File Not found"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment