trapping errors while using FTP.

Hello,

I have the following shell script to perform ftp:

ftp -n $HOST<<EOD
quote USER $USER
quote PASS $PASS
lcd $outputd
cd $dir
binary
put *.zip
quit
EOD

If any error is generated from this script then how to trap the error. For ex: let's say we entered wrong password then the return code from this shell script is always coming as 0. Even though there is a login error.

Do anybody have an idea how to trap ftp errors?

Appreciate your reply.
Radhika.

In general you could redirect the output STDOUT and STDERR of the ftp call to a log file and then query the log file for specific success or failure return codes to determine the status of the current ftp session. From this perspective you might have to create different log files for each ftp session and actively manage your logfiles too.

If there is any other way please advise. Thanks. Jerardfjay

Try this:

ftpresults=`ftp -inv $ip_box_name <<EOB
user $userid $password
put $ftp_file $downstream_name
bye
EOB`

ftp_ctr=`echo "$ftpresults" |grep "226" | wc -l`
echo $ftp_ctr
if [ $ftp_ctr = 1 ]
then
echo "FTP of " $file_name " to " $ip_box_name " was successful"
echo " "
else
echo="FTP failed"
fi

I am sorry, what does $ftpresults have in it.

Is it like stdout and stderr from ftp.sh?

My apology, I forgot part of the script in my editor. Please refer to my previous message for the script again.

ThankYou!!! All for your ideas and sample code. I am going to try them this morning.

Radhika.