我是Windows Perl的新手,我试图在Strawberry Perl上使用Net::SSH2。我有脚本的问题无法连接到设备列表。我可以连接到列表中的第一个设备,但无法连接到第二个,第三个等。我错过了什么?感谢您的任何建议。Perl Net :: SSH2模块无法在设备列表上工作
#!\usr\bin\Perl\bin\perl
use warnings;
use strict;
use NET::SSH2;
use MIME::Base64;
my $host = "C:/temp/devices.txt"; # input file
my $user = "XXX"; # your account
my $pass = "XXXXX"; # your password 64 bit mime
my $ssh2 = Net::SSH2->new();
my $result = "C:/temp/result.txt"; # output file
$ssh2->debug(1); # debug on/off
open(List, '<', "$host") or die "$!";
while(<List>) {
chomp $_;
unless ($ssh2->connect("$_")) {
print "Unable to connect : $_\n";
next;
}
my $dp=decode_base64("$pass");
unless ($ssh2->auth_password("$user","$dp")) {
print "Invalid Password\n";
exit;
}
my $chan = $ssh2->channel();
$chan->exec('sh ver');
my $buflen =100000;
my $buf = '0' x $buflen;
my $read = $chan->read($buf, $buflen);
warn 'More than ', $buflen, ' characters in listing' if $read >= $buflen;
open (OUTPUT, '>>', $result) or die "$!";
print OUTPUT "HOST: $_\n\n";
print OUTPUT "$buf\n";
print OUTPUT "\n\n\n";
print OUTPUT
$chan->close();
}
close (List);
这应该是`使用网络:SSH2`不使用NET :: SSH2`。它只能工作,因为Windows不区分大小写。 – 2011-12-14 22:43:04
你得到什么错误信息? – CanSpice 2011-12-14 22:47:38
@Brad Gilbert @我同意错字错误。 – Daniel 2011-12-14 23:11:55