[Kc] Has anyone used the Net:SSH2 perl Module

Daryl Fallin darylvf at gmail.com
Fri Jan 19 09:20:44 PST 2007


When I run the example code it completes the SCP and the SFTP calls with no
problem whatsoever, but when trying to use a channel it fails.  It appears
that everything works ok, authentication, etc, but I get zero output using a
channel.

I turned on debug and and this is the output I get:

daryl at seclab10:~/CPAN/Net-SSH2-0.09/example> ./read.pl
[user daryl]
Password: [user daryl]
libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type,
window_size, packet_size, ((void *)0) , 0 ) -> 0x8362f88
Net::SSH2::poll: timeout = 250, array[1]
- [0] = channel
- [0] events 1
- libssh2_poll returned 0
- [0] revents 0
Net::SSH2::Channel::DESTROY
Net::SSH2::DESTROY object 0x8180488
daryl at seclab10:~/CPAN/Net-SSH2-0.09/example>

Here is the code as I ran it for the above output:

#!/usr/bin/perl -w

# Sample Net::SSH2 code illustrating several ways to read the remote
# /etc/passwd file.

use Net::SSH2;
use IO::Scalar;

my $ssh2 = Net::SSH2->new;
$ssh2->debug(1);
die "can't connect" unless $ssh2->connect('localhost');
# use an interactive authentication method with default callback
# (if a password is provided here, it will forward it without prompting)
die "can't authenticate"
 unless $ssh2->auth(username => scalar getpwuid($<), interact => 1);

sub _read {
    my $handle = shift;
    while (my $line = <$handle>) {
        chomp $line;
        $line =~ s/:.*$//;
        print "found user '$line'\n";
    }
}

# (c) type it over a channel
$chan = $ssh2->channel;
$chan->exec('cat /etc/passwd') or die;
_read($chan);



Thank You

 - Daryl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/kc/attachments/20070119/07fa6d31/attachment.html 


More information about the kc mailing list