Operating System - HP-UX
1833758 Members
2410 Online
110063 Solutions
New Discussion

Re: retry process in ftp script...!!!!

 
rookie250
Occasional Contributor

retry process in ftp script...!!!!

hi #!/bin/bash
SERVER=10.89.40.35
USER=xyz
PASSWD=xyz

ftp -in $SERVER<user $USER $PASSWD
mkdir PPL
cd /path of remote dir
lcd /path of local dir
hash
bin
put
bye
<
The above ftp script i have to schedule in crontab at a particular instance of time run daily.
In the above ftp script i have to implement a retry process.
So that in the case if the transfer is stopped in between ftp for any reasons then after a gap of 15 mins the ftp session again retry to do the ftp.

This is done so that the person at remote server where the files are to be dumped get an idea that some problem lies in connectivity if ftp fails..after a no. of retries .

PLS if anybody cld help in writin the code for it..
5 REPLIES 5
Peter Godron
Honored Contributor

Re: retry process in ftp script...!!!!

Hi,
a couple of ideas:
1. you can check the return status of your ftp command and then rerun your ftp script
ftp
.
.
status=$?

2. you can check logfile for errors
ftp -in $SERVER << EOF > logile

3. you can compare filesizes after completion of ftp

4. We write put a start file at the beginning of the ftp script, then the datafile and finally we put a end file.

This way the receiver knows when the transfer started and that the datafile is complete, as we only transfer the end file after completing the data transfer.

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.

So far you have not awarded any points !

Bill Hassell
Honored Contributor

Re: retry process in ftp script...!!!!

The return code from ftp only refers to the ability to connect to the server -- nothing else. The reason is obvious: you can issue dozens of different commands (cd, dir, put, get, etc) and any of them could fail...so which command should affect the return code? So you must use ftp with a separate check, after the primary ftp process runs. You can reconnect with ftp and use dir to verify that the file exists and is the correct size. Note that you'll have to extract the dir line from stdout.


Bill Hassell, sysadmin
A. Clay Stephenson
Acclaimed Contributor

Re: retry process in ftp script...!!!!

This is one of the reasons why you should use Perl's Net::FTP module. It does error checking for free. The attached Perl script will put a file for you and do optional automatic retries on failure. Invoke as ftpput.pl -u for full usage but to do the task you listed above with 5 retries then:

ftpput.pl -h ${SERVER} -l ${USER} -p ${PASSWD} \
-B -d /remote_dir -t 5 file1 file2 file2
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "ftpput failed. status ${STAT}." >&2
fi

and if any operation such as cd fails a non-zero exist status will be returned to the shell.
If it ain't broke, I can fix that.
Robert Herron
Advisor

Re: retry process in ftp script...!!!!

I use LFTP (http://lftp.yar.ru/) for a similar purpose. It returns better exit codes than the native ftp program.
J Prafull
New Member

Re: retry process in ftp script...!!!!

Hi,

I have a ftp script which will take input from a parameter file and will transfer file. You can add some condition for exit code checking and rerun the loop / function..

May be helpful to you..
---------------------------------------------
while read dest_ip dest_user dest_pwd dest_file
do
if [[ -f $dest_file ]]
then
echo "Transferring $dest_file file."
{
echo open $dest_ip
echo user $dest_user $dest_pwd
echo put $dest_file $dest_file
echo close
} | ftp -inv
check=$?
echo "$dest_file file transfer complete."
fi
done < mapfile
---------------------------------------------
the mapfile contains entries like below.

Destnation_Svr_Name/IP ftp_usr_name passwd file_2transfer