Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > A timeout question using Net::FTP

Reply
Thread Tools

A timeout question using Net::FTP

 
 
Trudge
Guest
Posts: n/a
 
      07-28-2012
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?
--

 
Reply With Quote
 
 
 
 
Trudge
Guest
Posts: n/a
 
      07-28-2012
On Saturday, July 28, 2012 7:23:56 AM UTC-4, Ben Morrow wrote:
> Quoth Trudge:
>
> > 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.
>
>
>
> Ben


Thank you Ben (again) for clearing something up for myself and possibly others. That gives me a starting point.
--
Amer Neely

 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      08-06-2012
On 08/05/12 18:04, Cal Dershowitz wrote:
> On 07/28/2012 05:23 AM, Ben Morrow wrote:
>>
>> Quoth Trudge<>:
>>> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Timeout::timeout(time) question - or.. What am I missing here? Mikel Lindsaar Ruby 2 08-02-2008 12:06 PM
Timeout::timeout and Socket timeout Mark Probert Ruby 1 10-06-2004 09:30 AM
Session contents lost despite Session.Timeout = 3000; and <sessionState mode="InProc" cookieless="false" timeout="300"> Carpe Diem ASP .Net 3 02-23-2004 07:10 PM
web.config session timeout and forms authentication timeout Do ASP .Net 2 11-23-2003 02:27 PM
Re: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Bob Johnson ASP .Net 0 08-07-2003 12:52 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57