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

I am trying to use Net::SSH::W32Perl; I wrote the following test script

use strict; my $host = 'myhost'; my $user = 'user'; my $pass = 'password'; my $cmd = 'ls'; use Net::SSH::W32Perl; my ($ssh, $out, $err, $exit); my %args; $args{debug} = 1; $args{protocol} = 2; $ssh = new Net::SSH::W32Perl($host, %args); $ssh->login($user, $pass); ($out, $err, $exit) = $ssh->cmd("ls"); print "OUT: [$out]\n"; print "ERR: [$err]\n"; print "EXIT: [$exit]\n";

the screen gives the following output then hangs
TODDYCE: Reading configuration data /.ssh/config
TODDYCE: Reading configuration data /etc/ssh_config
TODDYCE: Connecting to myhost, port 22.
TODDYCE: Socket created, turning on blocking...
TODDYCE: Remote protocol version 1.99, remote software version
OpenSSH_3.5p1 FreeBSD-20030201
TODDYCE: Net::SSH::Perl Version 1.25, protocol version 2.0.
TODDYCE: No compat match: OpenSSH_3.5p1 FreeBSD-20030201.
TODDYCE: Connection established.
TODDYCE: Sent key-exchange init (KEXINIT), wait response.
TODDYCE: Algorithms, c->s: 3des-cbc hmac-sha1 none
TODDYCE: Algorithms, s->c: 3des-cbc hmac-sha1 none
TODDYCE: Entering Diffie-Hellman Group 1 key exchange.
TODDYCE: Sent DH public key, waiting for reply.
TODDYCE: Received host key, type 'ssh-dss'.
TODDYCE: Host 'newred.gradwell.net' is known and matches the host key.
TODDYCE: Computing shared secret key.
TODDYCE: Verifying server signature.
TODDYCE: Waiting for NEWKEYS message.
TODDYCE: Enabling incoming encryption/MAC/compression.
TODDYCE: Send NEWKEYS, enable outgoing encryption/MAC/compression.
TODDYCE: Sending request for user-authentication service.
TODDYCE: Service accepted: ssh-userauth.
TODDYCE: Trying empty user-authentication request.
TODDYCE: Authentication methods that can continue: publickey,password,keyboard-interactive.
TODDYCE: Next method to try is publickey.
TODDYCE: Next method to try is password.
TODDYCE: Trying password authentication.
TODDYCE: Login completed, opening dummy shell channel.
TODDYCE: channel 0: new client-session
TODDYCE: Requesting channel_open for channel 0.
TODDYCE: channel 0: open confirm rwindow 0 rmax 32768
TODDYCE: Got channel open confirmation, requesting shell.
TODDYCE: Requesting service shell on channel 0.
TODDYCE: channel 1: new client-session
TODDYCE: Requesting channel_open for channel 1.
TODDYCE: Entering interactive session.
TODDYCE: Sending command: ls
TODDYCE: Requesting service exec on channel 1.
TODDYCE: channel 1: send eof
TODDYCE: channel 1: open confirm rwindow 131070 rmax 32768
TODDYCE: input_channel_request: rtype exit-status reply 0
TODDYCE: channel 1: rcvd eof
TODDYCE: channel 1: output open -> drain
TODDYCE: channel 1: rcvd close
Has anyone got any idea how I can make this?
if i use $args{protocol} = 1; then it will work, but i want to use ssh2. thanks anyway!!

Replies are listed 'Best First'.
Re: Help...Issue with Net::SSH::Perl Module
by Khen1950fx (Canon) on Nov 25, 2010 at 21:46 UTC
    Net::SSH::W32Perl won't work with ssh1. Try this:
    #!/usr/bin/perl use strict; use warnings; use Net::SSH::W32Perl; my $host = 'localhost'; my $user = 'user'; my $pass = 'password'; my $cmd = 'ls'; my $ssh = new Net::SSH::W32Perl($host, debug => 1); $ssh->login($user, $pass); my ($out, $err, $exit) = $ssh->cmd($cmd); print $out;
      hi, thanks for you reply. i have tried your method, it doesn't work
      no matter Net::SSH::W32Perl or Net::SSH::Perl, if i specify
      the protocol to ssh2, then i won't work, it always hangs there.
      i find that, this module works fine on Linux, but it always has some issues on Windows.
        i find that, this module works fine on Linux, but it always has some issues on Windows.
        Do you mean the system running your perl program, or the target of the program? Is the target Linux?

        Do you have another ssh2 client program (like putty) that you can use to make sure your windows system has all the necessary libraries? It seems like the code can login, it's just when it tries to execute the command, something goes wrong.

        fnord