dolavoie has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to establish a SSH connection and I am running into this error. Can't call method "can" on an undefined value at C:/Perl/lib/Net/SSH/Perl/Packet.pm line 339, <GEN0> line 1. Any idea why I am getting this error ?

Replies are listed 'Best First'.
Re: SSH connection error
by neilwatson (Priest) on Feb 22, 2006 at 19:40 UTC
      #!/usr/local/bin/perl
      use strict;
      use Net::SSH::Perl;
      my %params;
      $params{'protocol'} = '2';
      $params{'port'} = '22';
      $params{'debug'} = 'true';

      my $ssh = Net::SSH::Perl->new("##", %params) or die "\n\nThere was an error : $!\n\n";
      $ssh->login("##", "##");
      my (my $stdout, my $stderr, my $exit2) = $ssh->cmd('ls -l');
      if ($stdout){print "Output:\n$_\n\n";}
      if ($stderr){print "Error:\n$_\n\n";}
      print "Exit Code:\n$exit2\n\n";
      The error is from the login line.
        I didn't see anything that seemed to be a show stopper however I thought this line looked a little odd
        $params{'debug'} = 'true';
        Usually I see this when creating a connection and debugging the session
        my $ssh = Net::SSH::Perl->new($srvr, protocol => 2, debug => 1);

        Maybe I'm just being picky. Perhaps you can try spelling it out like this and see if it helps. Are you receiving any debug information? If so could you please provide it. Also you could simplify this
        my (my $stdout, my $stderr, my $exit2) = $ssh->cmd('ls -l');
        with this
        my ($stdout, $stderr, $exit2) = $ssh->cmd('ls -l');
        Just some thoughts that might help. And don't forget the debug info.

        i don't see
        #!/usr/local/bin/perl -w
        I know.. sounds retarded in something so simple.. but then..

        this obviously means your object has not been made, made properly etc. so something is up with your %params, or the Net::SSH::Perl module, some dependency or something.. check the error log ofr the machine too! maybe the module is having an error or something else too.

        I would suggest first eliminate every simple explanation, and i think even 'hello world' should -w