Handling ftp error

I have a script which connects to remote server and ftp the files
It works fine, however if there is any failure in ftp connection can it be handled???

ftp log

ftp session start time is: Thu Jun 19 00:00:02 BST 2008
Not connected.
Not connected.
Interactive mode off.
Not connected.
Not connected.
Not connected.
success and proceed
ftp session end time is: Thu Jun 19 00:01:18 BST 2008

I have tried the following, but in vain

ftp -n $HOST > /tmp/ftp.worked 2> /tmp/ftp.failed <<END_SCRIPT
<code>
END_SCRIPT

EXITSTATUS=$?
if [ $EXITSTATUS != "0" ]
then
# handle the error...
fi

Can someone please help me?

Thanks

you can try the debug flag -d as well as the verbose flag -v. check your ftp man page