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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to retry FTP commands if unsuccessful and capture the failure status code.
# 1  
Old 11-11-2013
Code 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

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

Last edited by Don Cragun; 11-11-2013 at 07:58 PM.. Reason: Add CODE tags.
# 2  
Old 11-11-2013
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.
# 3  
Old 11-12-2013
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.

Code:
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to see the status of all the ftp put & get files logs and curent ftp transfer status ?

How to see the status of all the ftp put & get files logs and curent ftp transfer status if any active ftp running in the background ? (2 Replies)
Discussion started by: i4ismail
2 Replies

2. UNIX for Advanced & Expert Users

FTP commands to check the file status

Hi Experts, Can some one let me know the FTP commands to check the file status i.e i want to check whether my files are locked or in open status. I am connecting FTP from local machine. Regards, Spidy (1 Reply)
Discussion started by: spidy
1 Replies

3. Shell Programming and Scripting

How to capture 3 digit return code of ftp??

is it possible to capture the 3 digit return code of ftp commands in a local variable inside a shell script? Code: ftp remoteserver << EOFTP quote USER uid quote PASS pass prompt cd remote_directory mput file.txt bye EOFTP in the above script, if cd ... (4 Replies)
Discussion started by: Little
4 Replies

4. Shell Programming and Scripting

Retry upon FTP failure

I am using the following code in a C Shell script to transfer files to a remote server: ftp -n logxx.xxxx.xxx.xxx.com <<DO_FTP1 quote user $user_name quote pass $password ascii put $js_file_name bin put $FinalZipFile quit DO_FTP1 This code works great except on those rare occasions... (8 Replies)
Discussion started by: phudgens
8 Replies

5. UNIX for Dummies Questions & Answers

How to get successful/unsuccessful FTP logs in UNIX

Hi, We have one UNIX Server (Sun Solaris), and the files coming to this server from another server. The problem is, that server is continously sending files to our server via FTP. But the observation is that some files missing in our Server but in that server it shows the files FTPed... (2 Replies)
Discussion started by: vikash.rastogi
2 Replies

6. UNIX for Dummies Questions & Answers

How to list the Autosys jobs thats in failure status using Shell Script

Hello There, I am pretty much new to Shell Scripting and also to AutoSys. I would like to know how to list the Autosys jobs in FA status using shell scripting. I would like to get an email alert as and when any Autosys job fails. Also, it should give the path of the Log file. Could you please... (5 Replies)
Discussion started by: supragna
5 Replies

7. Shell Programming and Scripting

How to list the Autosys jobs thats in failure status using Shell Script

hello There, I am pretty much new to Shell Scripting and also to AutoSys. I would like to know how to list the Autosys jobs in FA status using shell scripting. I would like to get an email alert as and when any Autosys job fails. Also, it should give the path of the Log file. Could you please... (0 Replies)
Discussion started by: supragna
0 Replies

8. Shell Programming and Scripting

How to capture status code and echo a message

Im trying to execute application and its return code is below IF Status code=o echo "........" else Staus Code =-2 DJRE then echo "......" Can any one help me how to handle the status code and echo some message. (12 Replies)
Discussion started by: laknar
12 Replies

9. Shell Programming and Scripting

capture ftp return code..PLZ HELP

Hi all, i have written a code to ftp a file from one server to other.The ftp is happeneing successfully,but i am not able to capture the return code,to check if ftp has failed. plz help me to find out the return code....this is urgent below is the code i have written... (3 Replies)
Discussion started by: anju
3 Replies

10. Shell Programming and Scripting

retry process in ftp

hi #!/bin/bash SERVER=10.89.40.35 USER=xyz PASSWD=xyz ftp -in $SERVER<<EOF user $USER $PASSWD mkdir PPL cd /path of remote dir lcd /path of local dir hash bin put <file name> bye <<EOF The above ftp script i have to schedule in crontab at a particular instance of time run daily.... (2 Replies)
Discussion started by: rookie250
2 Replies
Login or Register to Ask a Question

Featured Tech Videos