1

首先,我是一个完整的 sftp 和 ssh 新手,对 Perl 很陌生。我正在尝试编写一个脚本来连接到远程服务器并检索文件。两台服务器都是windows 2003盒子。我已经在服务器上安装了一个 sftp 服务器,并且可以使用具有相同 IP 地址(出于安全原因从代码示例中删除)、用户名和我的代码中指定的端口号的 filezilla 客户端进行连接。

我拥有的代码连接块是:

my $sftp = Net::SFTP::Foreign->new(
    host    => 'xx.xxx.xxx.xxx', 
    user    => 'radiospx', 
    port    => '22', 
    ssh_cmd => "C:\\Program Files\\putty\\plink.exe",
    more    => [qw(-v -i )]
); 

$sftp->error and die " SSH connection failed: " . $sftp->error;

当我运行脚本时,我得到以下输出:

查找主机“sftp”无法打开连接:主机不存在 SSH 连接失败:与远程服务器的连接在 import.pl 第 34 行中断

谁能建议我哪里出错了。服务器肯定接受 sftp 连接,因为 filezilla 运行良好。

4

1 回答 1

2

-i您通过的plink 选项more需要一个参数:

my $sftp = Net::SFTP::Foreign->new(
    host    => 'xx.xxx.xxx.xxx', 
    user    => 'radiospx', 
    port    => '22', 
    ssh_cmd => "C:\\Program Files\\putty\\plink.exe",
    more    => ['-v', -i => "C:\\path\\to\\the\\private.key"]
); 

$sftp->error and die " SSH connection failed: " . $sftp->error;
于 2011-07-04T12:15:33.067 回答