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
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.