Re: [Ssh-sftp-perl-users] Net::SSH2 available on CPAN
Brought to you by:
dbrobins
From: <DGe...@wi...> - 2005-11-14 22:15:38
|
David, I have successfully tested Net::SSH2 as a replacement for Net::SFTP. I have installed tested this component on RedHat EL 3.0 and few other Linux distributions like Slackware and Gentoo. I have been using SFTP to collect various report files from server nodes on the network. SFTP proved to be complicated to configure and control. Particularly annoying part was that it would try user authentication with empty password even if I tried to force it to use public key authentication. The second disadvantage of using SFTP was its speed. On slow test machines, Pentium III with 256 MB RAM, it would take forever just to complete the authentication part of the transaction. On the same Pentium III machine SSH2 excelled and completed the file transfer in a half of a second. I am missing in SSH2 debug output similar to ssh -v. SFTP has option called debug that enables me to turn off/on this feature. I found it very useful when debugging issues. I don't know, maybe it is there I just couldn't find it. And at the end I'll mention a problem in using SSH2. If my script tries to get the list of authentication methods before the authentication takes place, the authentication would fail and error method is not returning any message/code back. This code produces the following: Authentication failed with my.network.server Errors 0 #!/usr/bin/perl use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2->connect('my.network.server'); my $alist = $ssh2->auth_list(); if ($ssh2->auth_publickey ( 'cntlserv', '/my-rsa-public-key-location/id_rsa.pub', '/my-rsa-private-key-location/id_rsa')) { print "Authentication OK with my.network.server\n"; $ssh2->scp_get('sar_data.xml'); } else { print "Authentication failed with my.network.server \n"; my @erors = $ssh2->error; print "Errors @erors \n"; } I am still learning to use SSH2 so there is always the possibility I missed something. Thanks, Dimitar David Robins <dbr...@cp...> Sent by: ssh...@li... 11/03/2005 02:03 AM To ssh...@li... cc Subject [Ssh-sftp-perl-users] Net::SSH2 available on CPAN As promised, I've created Net::SSH2, based on the excellent libSSH2 library (http://www.libssh2.org). Version 0.03 is up on CPAN (although it may not be indexed yet); see http://search.cpan.org/~dbrobins/Net-SSH2. It has several advantages over Net::SSH::Perl: - Fewer dependencies: it only requires libSSH2, which only requires OpenSSL (http://www.openssl.org), which is likely to be installed most places. - No SSH1 baggage (downside: no SSH1 support). This means it's able to offer new features and architecture. - SFTP and SCP support. - Supports many authentication and encryption methods (see list on libSSH2 home page). - Object-oriented: channel, SFTP, file, directory, and listener objects. - Win32 support (not tested, but libSSH2 works on Windows, so Net::SSH2 should too). - Channels can be reused (this should help the Cisco router folks). - Very fast C implementation. - Tied handle interface to make it possible to use getline/<> on remote files and channels. - 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 architecture; 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 = 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 => scalar getpwuid($<), interact => 1); sub _read { my $handle = shift; while (my $line = <$handle>) { chomp $line; $line =~ s/:.*$//; print "found user '$line'\n"; } } # (a) read using SCP my $passwd = 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 = $ssh2->sftp; my $file = $sftp->open('/etc/passwd') or die; _read($file); # (c) type it over a channel $chan = $ssh2->channel; $chan->exec('cat /etc/passwd') or die; _read($chan); -- David Robins ------------------------------------------------------- SF.Net email is sponsored by: Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php _______________________________________________ Ssh-sftp-perl-users mailing list Ssh...@li... https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users |