Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ftp script - capturing the return code. Help.

23 views
Skip to first unread message

S. Scott

unread,
Nov 1, 2002, 11:34:06 AM11/1/02
to
I have a communication script that I have automated. The script uses the
ftp protocol. What I do is ping the server to make sure it is up. If I get
a good return I then ftp to the server and do my send and receive. If I get
a bad return I skip the process and try again in 20 minutes.

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.


Tony Lawrence

unread,
Nov 1, 2002, 12:28:32 PM11/1/02
to


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


Frank da Cruz

unread,
Nov 1, 2002, 4:11:47 PM11/1/02
to
In article <04yw9.38641$Dn3.1...@dfw-read.news.verio.net>,
S. Scott <ssc...@lanter.com> wrote:
: I have a communication script that I have automated. The script uses the

: ftp protocol. What I do is ping the server to make sure it is up. If I get
: a good return I then ftp to the server and do my send and receive. If I get
: a bad return I skip the process and try again in 20 minutes.
:
: 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.
:
As Tony Lawrence suggested, see:

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

Stephen M. Dunn

unread,
Nov 1, 2002, 4:46:59 PM11/1/02
to
In article <apudjs$p54$1...@pcls4.std.com> Tony Lawrence <to...@aplawrence.com> writes:
$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.

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/

ScriptOmatic

unread,
Nov 2, 2002, 6:57:42 PM11/2/02
to

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.

L. Kovacs

unread,
Nov 6, 2002, 2:38:48 AM11/6/02
to
#!/bin/ksh
LOGFILE=log.txt


############################################################################
##
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
############################################################################
##


Rainer Zocholl

unread,
Nov 6, 2002, 4:48:00 PM11/6/02
to
(S. Scott) 01.11.02 in /comp/unix/sco/misc:

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

0 new messages