Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Net::SSH::W32Perl Just Hangs

by dorko (Parson)
on Sep 20, 2010 at 15:08 UTC ( #860858=perlquestion: print w/ replies, xml ) Need Help??
dorko has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'm trying to SSH from a Windows XP desktop to a Solaris box and run a command. I've installed Net::SSH::W32Perl on the Windows box. The script below seems to login correctly and send the command, but then it just hangs.

(For others researching this topic, the Web suggests commenting out lines 213 and 214 of Net:SSH::Perl.pm to get it working on Windows. If you install and use Net::SSH::W32Perl, it redefines the troublesome function in Net::SSH::Perl and you don't have to edit Net::SSH::Perl.)

I found this Re: Re: Re: Re: Re: SFTP hangs (winxp) and followed it's advise, but soulcage.net seems to be defunct.

Does anyone have any suggestions?

The script:

use strict; use warnings; use Net::SSH::W32Perl; $ENV{HOME} = 'C:\shaw\ssh'; my $host = 'super.cool.server'; my $ssh = Net::SSH::W32Perl->new($host, protocol => '2', debug => 1 ); my $user = 'supercooluser'; my $pass = 'supercoolpass'; $ssh->login($user, $pass); my $cmd = "pwd"; my($stdout, $stderr, $exit) = $ssh->cmd($cmd); print $stdout; print $stderr; print $exit;

The only results are the debug messages:

brentshaw: Reading configuration data C:\shaw\ssh/.ssh/config brentshaw: Reading configuration data /etc/ssh_config brentshaw: Connecting to xxx.xxx.xxx.xxx, port 22. brentshaw: Socket created, turning on blocking... brentshaw: Remote protocol version 2.0, remote software version Sun_SS +H_1.1.3 brentshaw: Net::SSH::Perl Version 1.34, protocol version 2.0. brentshaw: No compat match: Sun_SSH_1.1.3. brentshaw: Connection established. brentshaw: Sent key-exchange init (KEXINIT), wait response. brentshaw: Algorithms, c->s: 3des-cbc hmac-sha1 none brentshaw: Algorithms, s->c: 3des-cbc hmac-sha1 none brentshaw: Entering Diffie-Hellman Group 1 key exchange. brentshaw: Sent DH public key, waiting for reply. brentshaw: Received host key, type 'ssh-dss'. brentshaw: Host 'xxx.xxx.xxx.xxx' is known and matches the host key. brentshaw: Computing shared secret key. brentshaw: Verifying server signature. brentshaw: Waiting for NEWKEYS message. brentshaw: Send NEWKEYS. brentshaw: Enabling encryption/MAC/compression. brentshaw: Sending request for user-authentication service. brentshaw: Service accepted: ssh-userauth. brentshaw: Trying empty user-authentication request. brentshaw: Authentication methods that can continue: gssapi-keyex,gssa +pi-with-mic,publickey,password,keyboard-interactive. brentshaw: Next method to try is publickey. brentshaw: Next method to try is password. brentshaw: Trying password authentication. brentshaw: Login completed, opening dummy shell channel. brentshaw: channel 0: new [client-session] brentshaw: Requesting channel_open for channel 0. brentshaw: channel 0: open confirm rwindow 0 rmax 32768 brentshaw: Got channel open confirmation, requesting shell. brentshaw: Requesting service shell on channel 0. brentshaw: channel 1: new [client-session] brentshaw: Requesting channel_open for channel 1. brentshaw: Entering interactive session. brentshaw: Sending command: pwd brentshaw: Sending command: pwd brentshaw: Requesting service exec on channel 1. brentshaw: channel 1: open confirm rwindow 0 rmax 32768

I'm not sure why brentshaw: Sending command: pwd appears twice in the debug messages, but it does.

Cheers,

Brent

-- Yeah, I'm a Delt.

Comment on Net::SSH::W32Perl Just Hangs
Select or Download Code
Re: Net::SSH::W32Perl Just Hangs
by salva (Monsignor) on Sep 20, 2010 at 16:36 UTC
    Does anyone have any suggestions?

    Yes, use Net::SSH2 instead!

      I tried Net::SSH2 and I was able to get it working, but I can't get it to do what I want. The docs for it are a little slim. I don't suppose you've got any examples you can point me to?

      Cheers,

      Brent

      -- Yeah, I'm a Delt.
        I don't suppose you've got any examples you can point me to?

        This works for me on Windows Vista, connecting to a local linux box.
        use warnings; use strict; use Net::SSH2; my $buflen = 100; my $buf = '0' x $buflen; my $ssh2 = Net::SSH2->new(); $ssh2->connect('192.168.0.3') or die "Unable to connect Host $@ \n"; $ssh2->auth_password('user','password') or die "Unable to login $@ \n"; my $chan2 = $ssh2->channel(); $chan2->blocking(1); $chan2->exec('pwd'); $chan2->read($buf, $buflen); print $buf; $chan2->close;
        Allocating $buf like I've done above is not really necessary - the following should work just as well:
        use warnings; use strict; use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2->connect('192.168.0.3') or die "Unable to connect Host $@ \n"; $ssh2->auth_password('user','password') or die "Unable to login $@ \n"; my $chan2 = $ssh2->channel(); $chan2->blocking(1); $chan2->exec('pwd'); $chan2->read(my $buf, 100); print $buf; $chan2->close;
        See also the the Net::SSH2 test script for some examples of usage.

        Cheers,
        Rob
Re: Net::SSH::W32Perl Just Hangs
by Khen1950fx (Canon) on Sep 20, 2010 at 20:44 UTC
    You're printing $stdout, $stderr, and $exit---just print $stdout. This worked for me.
    #!perl use strict; use warnings; use Net::SSH::W32Perl; my $host = 'localhost'; my $user = 'user'; my $pass = 'pass'; my $ssh = Net::SSH::W32Perl->new($host, debug => 1); $ssh->login($user, $pass); my $cmd = 'pwd'; my($stdout, $stderr, $exit) = $ssh->cmd($cmd); print $stdout, "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://860858]
Approved by Gangabass
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2014-10-31 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (219 votes), past polls