Script to retry FTP commands if unsuccessful and capture the failure status code.

I am using the below code to ftp file onto another server

 FTP_LOG_FILE=${CURR_PRG_NAME}- ${FTP_FILE}-`date +%Y%m%d%H%M%S`.log

            ftp -ivn ${FTP_HOST} ${FTP_PORT} << ENDFTP >> ${EDI_LOG_DIR}/${FTP_LOG_FILE} 2>&1
            user ${FTP_USER} ${FTP_PSWD}
            lcd ${EDI_OUT_DIR}
            cd ${FTP_DIR}
            put ${FTP_FILE} ${FTP_FILE_BASE}_${DOMAIN}.${FTP_FILE_EXT}
            quit
ENDFTP

I want the script to try Ftping files for 3 times if the ftp is not successful. Note that I can not check the file on remote server as the file is removed from there as soon as it reaches.

What unix o/s and what ftp client are you using? Have you tested this script. What is the exist status if it works and it fails (echo $?). Note: the traditional method for ftp clients is the use of a .netrc file.

As you are using the -v flag, you should get useful output in your log file. Have a follow up step that reads it an d looks for errors, typically preceded with a three digit code of 400 or above.

egrep "^[4-9][0-9][0-9] " ${EDI_LOG_DIR}/${FTP_LOG_FILE} | grep -v bytes transferred

I have added the grep -v as it is possbile that you will be sendind 400 to 999 bytes and this will be seen as an error.

I hope that this helps.

Robin
Liverpool/Blackburn
UK