[32487] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3752 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 6 16:09:16 2012

Date: Mon, 6 Aug 2012 13:09:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 6 Aug 2012     Volume: 11 Number: 3752

Today's topics:
    Re: A timeout question using Net::FTP <glex_no-spam@qwest-spam-no.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 06 Aug 2012 12:44:42 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: A timeout question using Net::FTP
Message-Id: <5020028a$0$9079$815e3792@news.qwest.net>

On 08/05/12 18:04, Cal Dershowitz wrote:
> On 07/28/2012 05:23 AM, Ben Morrow wrote:
>>
>> Quoth Trudge<trudge@gmail.com>:
>>> I have a script to download files. It checks the remote and local
>>> directories, and downloads any new files from the remote location.
>>>
>>> Here is part of my code:
>>> my $ftp = Net::FTP->new
>>> (
>>> "ftp.xxx.yy",
>>> Timeout => 3600,
>>> Debug => 0
>>> ) or die "Could not connect: $@\n";
>>>
>>> My question is, what units are the Timeout option in? The docs don't
>>> make it clear, and I'm guessing the units are seconds. Anyone have a
>>> definitive answer?
>>
>> The timeout is passed to IO::Select, so it's in seconds, possibly
>> fractional.
>
> Idunno, Ben:
>
>
> $ perltidy safe_post11.pl
Why do we need to see this??

> $ perl safe_post11.pl my_ftp
You can make safe_post11.pl an executable so you don't have to type 
'perl' every time.

> ..........
> success is 22
> $ cat safe_post11.pl
> #!/usr/bin/perl -w
> use strict;
> use 5.010;
> use Net::FTP;
> use diagnostics;
>
> $| = 1; # Disable output buffering
>
> ## usage: perl safe_post11.pl server_name
> my $ident = 'my_ftp.txt';
> my ($config, $domain);
> $config = do($ident);
> unless ($config) {
> die("read error: $!") if $!;
> die("parse error: $@") if $@;
> }
>
> $domain = $config->{$ARGV[0]};
> die("unknown domain: $ARGV[0]") unless $domain;
>
> # printf("server\t%s\nuser\t%s\npass\t%s\n",
> # $domain->{domain},
> # $domain->{username},
> # $domain->{password});

We don't need to see most of the noise above.  Show only the
specific code that describes your problem.

>
> my $ftp = Net::FTP->new( $domain->{domain}, Timeout => 5 ) or die "Can't
> connect: $@\n";

> $ftp->login( $domain->{username}, $domain->{password} )
> or die "Couldn't login\n";
Always include the reason/message. When it fails it might tell you why.
>
> for (1..10) {
> print '.';
> sleep 1;
> }
> print "\n";
>
> my @r = $ftp->ls();
> my $success = scalar(@r);
> print "success is $success\n";
That seems like an odd way to determine success.
>
> # close $ftp;
> $
>
> cpan says 120 is the default, but haven't I changed that?

Yes.  You don't show the failure that is taking longer than 5
seconds to timeout though.

Using sleep there doesn't do anything to show there's a problem. The
login() will wait for the connection to succeed or fail. The timeout
is how long to wait around for a response, it doesn't have anything to
do with how long it's connected.

If you want to do something with the connection based on elapsed
time, see perldoc -f alarm . Usually that's not needed because
it usually connects and you do what's needed and close the connection,
or you can't connect or the operation times out and you handle the error.




------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3752
***************************************


home help back first fref pref prev next nref lref last post