[Ssh-sftp-perl-users] Net::SSH2 available on CPAN
Brought to you by:
dbrobins
From: David R. <dbr...@cp...> - 2005-11-03 06:05:26
|
As promised, I've created Net::SSH2, based on the excellent libSSH2 library= (http://www.libssh2.org). =A0Version 0.03 is up on CPAN (although it may n= ot be indexed yet); see http://search.cpan.org/~dbrobins/Net-SSH2. It has several advantages over Net::SSH::Perl: =2D=A0=A0=A0=A0=A0=A0=A0Fewer dependencies: it only requires libSSH2, which= only requires OpenSSL (http://www.openssl.org), which is likely to be inst= alled most places. =2D=A0=A0=A0=A0=A0=A0=A0No SSH1 baggage (downside: no SSH1 support). =A0Thi= s means it's able to offer new features and architecture. =2D=A0=A0=A0=A0=A0=A0=A0SFTP and SCP support. =2D=A0=A0=A0=A0=A0=A0=A0Supports many authentication and encryption methods= (see list on libSSH2 home page). =2D=A0=A0=A0=A0=A0=A0=A0Object-oriented: channel, SFTP, file, directory, an= d listener objects. =2D=A0=A0=A0=A0=A0=A0=A0Win32 support (not tested, but libSSH2 works on Win= dows, so Net::SSH2 should too). =2D=A0=A0=A0=A0=A0=A0=A0Channels can be reused (this should help the Cisco = router folks). =2D=A0=A0=A0=A0=A0=A0=A0Very fast C implementation. =2D=A0=A0=A0=A0=A0=A0=A0Tied handle interface to make it possible to use ge= tline/<> on remote files and channels. =2D Polling interface for channels and listeners. I will continue to maintain Net::SSH::Perl, but for certain issues (such as= channels) I will refer people to Net::SSH2. What's needed now is people to test the new module and to comment on the ar= chitecture; changes certainly can and will be made at this point. Sample code illustrating several ways to read /etc/passwd: use Net::SSH2; use IO::Scalar; my $ssh2 =3D Net::SSH2->new; 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 =3D> scalar getpwuid($<), interact =3D> 1); sub _read { my $handle =3D shift; while (my $line =3D <$handle>) { chomp $line; $line =3D~ s/:.*$//; print "found user '$line'\n"; } } # (a) read using SCP my $passwd =3D IO::Scalar->new; die "can't fetch /etc/passwd" unless $ssh2->scp_get('/etc/passwd', $passwd); $passwd->seek(0, 0); _read($passwd); # (b) read a line at a time with SFTP my $sftp =3D $ssh2->sftp; my $file =3D $sftp->open('/etc/passwd') or die; _read($file); # (c) type it over a channel $chan =3D $ssh2->channel; $chan->exec('cat /etc/passwd') or die; _read($chan); =2D-=20 David Robins |