1833589 Members
3976 Online
110061 Solutions
New Discussion

Checking FTP Transfers

 
Fuad_1
Regular Advisor

Checking FTP Transfers

I have written the following script file to automate a daily transfering files using VPN. For some reason, some files are not successfuly transfered. I run a cron job every minute and forward the output. How I can automate the check for failures in file transfer?
cd /appl/
ls LKL* | read LINE
ftp -n x.x.x.x << EOF
user xxxxx xxxxx
type ascii
prompt
hash
put $LINE
bye
EOF
echo $LINE
date
mv $LINE /home/backup_out
the cron is :
* 17-22 * * * /home/taut.sh >> /home/taut.log
Set goals, and work to achieve them
4 REPLIES 4
Mark Grant
Honored Contributor

Re: Checking FTP Transfers

The only surefire way of doing this is to compare the files after the transfer as in

remsh machine2 cat $LINE | cmp - $LINE

You can test the output of this. i.e. if there is any output, the transfer failed.
Never preceed any demonstration with anything more predictive than "watch this"
Brendan Newport_2
Frequent Advisor

Re: Checking FTP Transfers

It's probably not accurate enough, but I have a script that performs a regular ftp session and a quick evaluation of the result (this one just checks for one file, so take the wc -l out for multiple files, and search for "Failed";

ftp -v <open xxxxx
cd xxxx
lcd $CTNL_DIR
put $_FTPFILE
bye
EOF
_FTPRESULT=`grep -i "Transfer complete" $_FTPCHECK | wc -l`
if [ $_FTPRESULT = 1 ]
then
echo "FTP of XML file worked OK" | tee -a $LOGFILE
return 0
else
mailx -s "Alert from `hostname` failed to be FTP'd to xxxx at `date`"
return 1
fi
Graham Cameron_1
Honored Contributor

Re: Checking FTP Transfers

It could be that your script does something you did not intend.
If you have more than one file whose name begins LKL, your script will only pick up the first one.
There are a number of ways round this.
eg - use "mput LKL*" instead of "put $LINE". This is the easiest to script.
Or you could use "ls -1" to generate a list of files and process them one at a time.
--
In terms of capturing FTP session output, as per previous post, capture session output using "ftp -n x.x.x.x << EOF >LOG 2>$1" and use grep to check the log file.
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
A. Clay Stephenson
Acclaimed Contributor

Re: Checking FTP Transfers

Rather than doing silly stuff with commands after the fact, the far better way is to test as each file is transferred and possibly automatically attempt a re-transmit. Perl's Net::FTP module makes this trivially easy. Perl 5.6.1 that ships with current HP-UX already has the module but if using earlier versions then you will need to download and install the Net::FTP module from www.perl.org/CPAN.

All you have to do, is
ftpput.pl file1 file2 file3 and modify the code to do the appropriate cd's and logins.
Net::FTP also recoginizes .netrc conventions so that you don't even have to put passwords in the script -- the comments are in the code.


ftpput.pl file1 file2 file3
STAT=${?}

if ${STAT} is zero, you KNOW all the file transfers were ok.
If it ain't broke, I can fix that.