Ftp Status Check

Hi,

I'm using the below script to ftp the file passed as 3rd argument. I'm passing the source and destination directory as 1st and 2nd argument. This script does the ftp successfully.

The script displays the echo before ftp stmt and does the ftp and does not display the stmts after that check the status of ftp...

Am I doing something wrong here?

echo "B4 ftp: `date '+%d/%m/%Y %T'`" |tee -a $LOGFILE 2>&1
ftp -v -n -i ${IP_ADDRESS} <<==eoftp== >> $LOGFILE 2>&1
user ${USERID} ${PASSWORD}
lcd ${1}
cd ${2}
put ${3}
bye
==eoftp==
ret_val=$?
echo "After ftp: `date '+%d/%m/%Y %T'`" |tee -a $LOGFILE 2>&1
echo "ret_val..= ${ret_val}" |tee -a $LOGFILE 2>&1
if [[ ${ret_val} -ne 0 ]]
then
echo "FTP failed..." |tee -a $LOGFILE 2>&1
else
echo "FTP Successful..." | tee -a $LOGFILE 2>&1
fi

Thanks in advance,

AC

You cannot use the return-code from ftp. Instead, you must to grep your logfile to ensure that there were no error messages from either the cd or put commands.
e.g. grep "^550" should show any "No such file or directory" messages if you try to cd to a directory that does not exist.

This may be a trivial solution ... but can try this ... works fine till now for me ...

(
echo "
open destination_machine_ip
user username password
bin
cd \"destination_directory\"
dir filename
mget filename
close
"
) | ftp -nv > TempLogFtp.log
if [ $? -ne 0 ]; then
echo "--------------------------------------------------" >> $LOGFILE
echo "`date` FTP Failed" >> $LOGFILE
echo "--------------------------------------------------" >> $LOGFILE
exit 1
else
DESTINATION_FILE_SIZE=`grep "Opening BINARY data connection" TempLogFtp.log|cut -d"(" -f2|cut -d" " -f1`
SOURCE_FILE_SIZE=`ls -l filename|tr -s " "|cut -d" " -f5`
if [ $DESTINATION_FILE_SIZE -eq $SOURCE_FILE_SIZE ]; then
FILENAME="`ls filename`"
echo "Download Successful. Filename: $FILENAME" >> $LOGFILE
else
echo "--------------------------------------------------" >> $LOGFILE
echo "`date` Download Failed" >> $LOGFILE
echo "--------------------------------------------------" >> $LOGFILE
exit 1
fi
fi

U can chk for other exit code such as 550 too as given by Ygor

Thanks for the information.

Thanks for the information.