My issue is that the server returns a good return but when I connect the ftp
session hangs. What I need to do is do a test to make sure the ftp process
finished properly before I delete my file. If the ftp process does not
complete correctly then I need to not delete the file and try again in my
next cronned schedule.
Any and all suggestions are appreciated.
Regards,
Shannon S.
There are a couple of ways to handle this.
My preference is to use Perl and Net::Ftp
Or, you can use the scripting capabilities of programs like Kermit.
http://www.columbia.edu/kermit/ftpclient.html
http://www.columbia.edu/kermit/ftpscripts.html
You could also use Expect ( http://aplawrence.com/Books/expect.html )
but that's fairly painful.
Finally, you can spin off your script to background and set off another
script that watches for it to finish, checks that it did what it was
supposed to do etc. Not the most fun to do, but it can be done.
--
Please note new phone number: (781) 784-7547
Tony Lawrence
Unix/Linux Support Tips, How-To's, Tests and more: http://aplawrence.com
Free Unix/Linux Consultants list: http://aplawrence.com/consultants.html
http://www.columbia.edu/kermit/ftpscripts.html
It discusses exactly this case (if you read the whole thing).
: If the ftp process does not
: complete correctly then I need to not delete the file and try again in my
: next cronned schedule.
:
This topic is also covered in much greater detail here:
http://www.columbia.edu/kermit/case10.html
This discussion concerns Kermit protocol transfers, rather than FTP, but
the issues -- and the client -- are the same.
- Frank
Use groups.google.com's advanced search option to search
comp.unix.sco.misc for timed_run and you'll get another idea - some
shell script code from John Dubois which will kill your FTP session if
it takes too long.
As usual, there are lots of ways to skin a ... er, I don't think
my cat likes that expression!
--
Stephen M. Dunn <ste...@stevedunn.ca>
>>>----------------> http://www.stevedunn.ca/ <----------------<<<
------------------------------------------------------------------
Say hi to my cat -- http://www.stevedunn.ca/photos/toby/
try the file set in ftp.opensysmon.com/pub/plugins/autoftp.tar.gz
designed for this problem.
--
http://ftp.opensysmon.com is a shell script archive site with an
open source system monitoring and network monitoring software package.
Many platforms are supplied already compiled.
############################################################################
##
gen_ftp() {
print 'put file.dat' > ftpcmd.txt
print 'chmod 755 file.dat' >> ftpcmd.txt
ftp ftp.something.com < ftpcmd.txt
if (( $? != 0 )) ; then
mydatetime=$( date )
print "$mydatetime FTP error" >> $LOGFILE
return 1
else
mydatetime=$( date )
print "$mydatetime FTP done" >> $LOGFILE
fi
return 0
}
############################################################################
##
# M A I N
mydatetime=$( date )
gen_ftp |&
pid=$!
print "$mydatetime waiting for pid=$pid" >> $LOGFILE
exitcode="timeout"
for i in 1 5 10 15 20
do
(( sleeptime=i * 5 ))
sleep $sleeptime
kill -0 $pid
if (( $? != 0 )) ; then
mydatetime=$( date )
print "$mydatetime gen_ftp over" >> $LOGFILE
wait $pid
exitcode=$?
break
else
mydatetime=$( date )
print "$mydatetime gen_ftp still running" >> $LOGFILE
fi
done
mydatetime=$( date )
if [[ $exitcode = "timeout" ]] ; then
print "$mydatetime gen_ftp timed out" >> $LOGFILE
# you may want to kill the ftp-session here
# kill -9 $pid
elif [[ $exitcode != 0 ]] ; then
print "$mydatetime gen_ftp failed" >> $LOGFILE
else
print "$mydatetime gen_ftp ok" >> $LOGFILE
fi
############################################################################
##
Did you ever mention to use "mirror.pl"?
A perl script that solved all those ugly ftp-problems approx 10 years ago...
(Just a hint: there are several "tastes" ftp dialog)
It checks timeout, sizes, avoids storing incomplete
files while downloading, skips non-new files etc.
Your problem description sounds very much reinventing that wheel.
If you are copying over the internet use "sftp" or "scp".
HTH