Zentara is right about what you need to do, but a fuller explanation
of the solution would have been:

Net::SFTP is throwing an exception when it cannot make the
connection.  If the exception is not caught, it will cause your
program to exit.  The way you catch exceptions in Perl is to wrap the
code that throws them in an eval block.  After the eval block, the
exception will be stuffed into the $@ variable, so you can examine
that variable to see if there is some kind of useful information there
about what the exact problem was.  

--Dks


On Sat, Dec 14, 2002 at 09:50:33AM -0500, zentara wrote:
> On Fri, 13 Dec 2002 11:10:54 -0500, [EMAIL PROTECTED] (Ian
> Zapczynski) wrote:
> 
> >Unfortunately, using the || as below doesn't change the behavior.  Once 
> >my script tries to make the connection and can't, it exists with a 
> >"connection failed to $host, etc. etc." message, whether I use warnings 
> >or diagnostics or neither.  If anyone can help me understand why this 
> >may be or if they experience the same, this would be terribly helpful. 
> > As I mentioned, I need to be able to trap this error and continue 
> >processing if a connection fails.
> 
> Wrap it in an eval statement.
> 
> ######################################################3
> #!/usr/bin/perl -w
> use strict;
> use Net::SFTP;
> 
> my $sftp = undef;
> eval{
> $sftp = Net::SFTP->new("localhost", 
>                                              user=>"zzztester",
>                                      password=>"zzztest",
>                   );
> };
> if ($@) { print "Sftp connection failed:\n  $@\n"; }
> 
> if (! $sftp) {
>   print "I can't connect!\n";
> }else{
>   print "SUCCESS!\n";
> }
> ########################################################
> 
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to