ftp return code not working

below is my code , but for some reason the return part is not working, only file transfer is happening and no exit status is checked .please me help me to fix this code

#!/bin/sh
#set -vx
ftp -nv sitelocation  << !
   user username password
   lcd localdir
   cd /remote dir
   mget *.*
   close
   bye
!
return_code=$?
echo $return_code
case "$return_code" in
    0)
         echo "  "
         date +"File transfer successfully at %T on %D"
         exit 0;;
esac
echo " "
date +" File transfer failed  at %T on %D"
exit 1;

Thanks

Hello gwrm.

Is the code you posted, the actual code?

The closing pling (!) is missing:

ftp -nv sitelocation  << !
   user username password
   lcd localdir
   cd /remote dir
   mget *.*
   close
   bye
!

The return code of ftp is always 0 because it is just returning that it has been successfully called. The internal return codes of ftp like for example:

200 PORT command successful

can't be cought outside ftp by evaluating $?. This could achieved by parsing the log of the ftp session for example. Maybe scp is an alternative for you too. It is key based, encrypted and you can immediately check $?.

---------- Post updated at 10:17 AM ---------- Previous update was at 10:16 AM ----------

I added his missing ! and reformatted the code since he said the ftp itself worked. Just as side note.

Hi scottn
Thanks for the reply
the script i posted already has closing pling !, I'm not so sure wat you are refering to

   lcd localdir
   cd /remote dir
   mget *.*
   close
   bye
!

---------- Post updated at 04:48 AM ---------- Previous update was at 04:46 AM ----------

[/COLOR]hi zaxxon,

can you please paste your reformatted code

thanks

Uhm you still do not use code tags in your post - change this please. I reformatted your original post up in the top.