Re: [Ssh-sftp-perl-users] [Fwd: Re: Trap connection errors somehow instead of just letting the whol
Brought to you by:
dbrobins
From: Hans de G. <ha...@da...> - 2012-03-29 06:31:29
|
Hi, I tried eval with {} and this time it actually worked. sub copy_file { my $source=shift; my $dest=shift; my $f; eval{$f=$sftp->get($source,$dest)}; if ($@) { print "Connection error!!\n"; #try to reconnect here.. } } Thanks a lot every one. On Wed, 28 Mar 2012 10:15:46 -0500 "Nigel Reed" <ni...@sy...> wrote: > I didn't CC the list in my reply to Hans. This will be useful to others > I'm sure. > > > ---------------------------- Original Message ---------------------------- > Subject: Re: [Ssh-sftp-perl-users] Trap connection errors somehow instead > of just letting the whole script die. > From: "Nigel Reed" <ni...@sy...> > Date: Wed, March 28, 2012 10:14 am > To: "Hans de Groot" <ha...@da...> > -------------------------------------------------------------------------- > > > Hans de Groot wrote: > > But some times during a session (lots of data) the script dies with: > > > > Connection failed: Connection reset by peer > > at /usr/lib/perl5/site_perl/5.8.8/Net/SFTP.pm line 568 > > > > But I need the script to keep running and detect these errors and try to > > reconnect and resume copyinf file. But it seems it's out of my hands? > > > I do something like this. > > eval { $ssh = Net::SSH::Perl->new($host, ( protocol => 2, > debug=>$debug )); }; > if ($@) { print "EREOR! Cannot connect to $host $@\n"; > noconnect($host); $pm->finish; next; } else { print "CONNECT > $host\n"; } > > Basically, wrap your command in an eval, then use $@ to determine if there > was a connection. > > -- > Nigel Reed > > > > > -- > Nigel Reed > > > > > ------------------------------------------------------------------------------ > This SF email is sponsosred by: > Try Windows Azure free for 90 days Click Here > http://p.sf.net/sfu/sfd2d-msazure > _______________________________________________ > Ssh-sftp-perl-users mailing list > Ssh...@li... > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users -- Hans de Groot <ha...@da...> |