Status check of Automated FTP

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.

}

You probably should do a second ftp but this time
list the relevant directory to a logfile. Then exit
ftp and grep for the specific file that was 'put'
in the logfile.

.....

Would it not be better to do a checksum before you put <file>,
then send the checksum file with original file. Once original file
arrives with checksum file, do verification on checksums.

Is this not 100% effective in a precise automated system?

The checksum idea requires the recipient to do the checking. I think that the OP want a way for the sender to verify that the file arrived without help from the recipient.

Why not capture the output from ftp and grep for success?

ftp -vin < ${CMD_FILE} 1> ${FTP_LOG} 2>&1
grep -q 'Transfer complete' ${FTP_LOG}
if [ $? -ne 0 ]
then
echo error
fi