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

Hi all

I have the same problem as described here. This problem was resolved in this thread.

The only problem is that it seems the soulcage repo has disappeared, and I don't have a clue as to where to get the "working" module now.

Anyone have an idea?

Anyway, here's my code:

#! /usr/bin/perl use strict; use warnings; use Net::SSH::W32Perl; use Data::Dumper; my $host = "xxx.xxx.xxx.xxx"; $ENV{HOME} = "C:\\temp"; my $sftp = Net::SSH::W32Perl->new($host, protocol => '2', debug => '1' +); $sftp->login("user", "password"); my ($out, $err, $exit) = $sftp-> cmd("ls"); exit;

And here is the output:

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

It just hangs after the last line. I'm pretty sure the Net-SSH-W32Perl module from the soulcage repo will solve my problem, if I only knew where to get it.

Regards

Scrat

Replies are listed 'Best First'.
Re: Net-SSH-W32Perl hanging (Solved)
by cmv (Chaplain) on Apr 16, 2009 at 20:39 UTC
    Folks-

    I spent a few days tracking this down (I really like Net::SSH::Perl and friends) and believe I have a solution.

    Hope it helps.

    -Craig

    Short answer

    A bug was introduced in Net::SSH::Perl (in version 1.34 and maybe earlier), that breaks Net::SSH::W32Perl, and gives you the symptom above. I will be submitting a bug report.

    More Details

    The bug appears in the file:
    c:\Perl\site\lib\Net\SSH\Perl.pm

    In order to fix the problem, I modified these lines:

    my $proto_class = join '::', __PACKAGE__, ($proto == PROTOCOL_SSH2 ? "SSH2" : "SSH1");
    To look like this (what the original code was):
    my $proto_class = $ssh->protocol_class($proto);
    This fixes the problem for me.

    Even More Details

    If you are using Net::SSH::W32Perl to access the Net::SSH::Perl modules from your windows PC, the original Net::SSH::Perl code would correctly set

    $proto_class='Net::SSH::W32Perl::SSH2'
    The new version 1.34 of Net::SSH::Perl will incorrectly set
    $proto_class='Net::SSH::Perl::SSH2'
    which causes Net::SSH::W32Perl all sorts of grief, and your remote commands end up hanging.

    Some folks have asked for a recipie for installing Net::SSH::Perl & friends on a PC. Here is how I do it...

Re: Net-SSH-W32Perl hanging
by tokpela (Chaplain) on Feb 12, 2009 at 09:12 UTC
    Hi Scrat,

    You should use Net::SSH2 for SFTP on Windows. There is a PPM available for this module.

      Thanks for the reply. Although the suggested module didn't work for me I managed to find something in the end that should satisfy the requirement:

      Requirement: Periodically scan a directory on a Windows Server and compile a list of xml files if there are any present. SFTP that list of files to a destination SFTP server. Once the transfer is successful remove them from the local server.

      This thread got me thinking about using a simple WinSCP script to do the file transfer.

      Using WinSCP Version 4.1.8 (which supports Hostkey validation during the authentication process with the -hostkey option) I built the following script:

      option batch on option confirm off open sftp://user:password@servername:22 -hostkey="hostkey" lcd d:\localdir cd /remotedir option transfer binary put *.xml close exit

      In the end a Windows Service will periodically scan a directory. During each iteration, should we find any xml files, we will call the above script to connect and transfer the files. If the transfer is successful the xml files will be removed locally afterwards.

      There are still some loopholes that would need to be resolved, like securing the script (encryption maybe?), more efficient error checking during the actual transfer, to name but a few. I'm still considering some ideas.

      Scrat