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.
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.