在无效上下文中呼叫连接



我正在尝试使用 Net::SSH2在以下perl代码中,但是我会遇到此错误。

在void上下文中呼叫连接在test.pl第9行。
net :: ssh2:无法连接到xx.xx.xxx.xx:ssh:test.pl line9。

的糟糕文件描述符
use strict;
use Net::SSH2;
#use Net::SSH2::Expect;
#my $Hostname = 'xx.xx.xx.xx';
my $ssh = Net::SSH2->new();
#$ssh->timeout(10);
$ssh->connect('xx.xx.xx.xx');

有人可以帮我吗?

将连接方法保留在内部如果或使用die_with_error帮助我修复了代码。

use strict;
use Net::SSH2;
my $ssh=Net::SSH2->new();
if($ssh->connect('xx.xx.xx.xx'))
  {
     print "successfully connected";
     $ssh->auth_password('username','password') or $ssh->die_with_error;
  }

最新更新