execute ftp script until it succeeds

I have a ftp script that occasionally fails (connection lost error). I would like to execute the ftp command until it succeeds. Would the script below work?

while [ $? <> 0 ]
  do
    ftp -i -n <<EOF >> $LOG
    open $FTP_HOST
    user $FTP_LOGIN $FTP_PASSWD
    put filename.csv
    bye
    quit
    EOF

No matter what happens inside the ftp itself, it will most probably return a RC of 0. So you'll might want to check for the 3-digit ftp codes the client shows when entering ftp commands. I guess there is some -v (verbose) option that turns it on.
With that (there is a missing "done" at the end btw.) you will most probably have an infinity loop.

Also if possible I recommend setting up ssh and the use of scp instead. It is encrypted and when keys are exchanged there will be no need to supply passwords etc.

Oops, I forgot the "done" command

So are you saying that a "while" statement like this will result in an loop?

Correct, that is one of the points I mentioned.

Check it out yourself, add some ftp commands that will fail like a put for a file that does not exist and then print out the $? of your ftp. Most probably it will be still 0.

That's too bad then. I'll have to go back to the drawing board. Thank you for responding

var="Not connected."
while [ "$var" = "Not connected." ]
do
var=$(ftp -i -n <<EOF
open "$FTP_HOST"
quote user "$FTP_HOST" 
quote pass "$FTP_PASSWD"
binary
ls  
bye   
EOF)
var=$(echo "$var" | awk 'NR==1{print $1,$2}')
done