Re: [Ssh-sftp-perl-users] Trap connection errors somehow instead of just letting the whole script d
Brought to you by:
dbrobins
From: Hans de G. <ha...@da...> - 2012-03-29 06:14:32
|
Hello, What I tried before I posting here was this: 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.. } } But what happened was that the script did not die, but also no error message or something. I mean it did not print the "connection error!!" message. It just sat there doing nothing. But maybe the eval should be betwen {} instead of () ? Could that explain the "waiting"? Thanks for your help. Hans On Wed, 28 Mar 2012 22:44:44 +1000 (EST) "Christian King" <chr...@ch...> wrote: > Wrap the relevant call(s) in an eval {} block. > > If there is a syntax error or runtime error, or a die statement is > executed, eval returns undef in scalar context or an empty list--or, for > syntax errors, a list containing a single undefined value--in list > context, and $@ is set to the error message. > > http://perldoc.perl.org/functions/eval.html > > The execution will drop out of the code within eval {} and back to your > program when there is an error. > > > Hello list, > > > > I made a sftp script that should copy stuff from a to b. > > > > 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? > > > > The script dies in the net::sftp module. > > > > Are there any config settings I could pass to net:sftp or maybe net::ssh? > > > > It is rather irritating the way it works now. > > > > The only work arround I could think of now is have my script call an > > other script that copies the files and when it dies I can see it in the > > output. But tracking whichs files have been copied is a lot harder this > > way. > > > > Regards, > > > > > > -- > > Hans de Groot <ha...@da...> > > > > > > ------------------------------------------------------------------------------ > > 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...> |