Hi,
I've following code fragment as a part of 1 of my scripts.
Function is supposed to perform automated ftp to designated host.
Here are the details:-
#! /usr/bin/ksh
< some code>
perform_ftp()
{
#Assume that file to transfer is available in current directory
TMP_FILE=/tmp/$$-FTP
echo " open <hostname>" > ${CMD_FILE}
echo "user <user name> <password> " >> ${CMD_FILE}
echo "put <some file> " >> ${CMD_FILE}
echo "bye" >> ${CMD_FILE}
ftp -vin < ${CMD_FILE} 1> /dev/null 2>>${ERROR_LOG}
if [ $? -ne 0 ]; then
echo "\nError Transmitting the file"
rm -f ${CMD_FILE}
exit 1
else
echo "\nSuccessfully Transmitted report file."
fi
rm -f ${CMD_FILE}
}
The problem with above function is that even though the actual put command is not successful, say because file system is full or lack of appropriate permission, script will always report that file was transmitted successfully.
This is because last command "bye" executed as a part of FTP is always successful & "$?" always returns 0.
Any pointers how can I check whether "put" command was successful or not?
P.S. :- Requirement is not to log output of ftp command in ERROR_LOG. It has to be discarded, no matter whether FTP is successful or not.
}