如何在perl中使用私钥和密码通过sftp进行连接?

如何在perl中使用私钥和密码通过sftp进行连接?,perl,sftp,putty,Perl,Sftp,Putty,我一直在尝试使用perl连接到sftp服务器,我尝试了几个模块和puTTy,但没有成功 use Net::SFTP::Foreign; use Net::SFTP::Foreign::Backend::Net_SSH2; use Net::SSH2; my ($host) = 'xxx.xxxx.xxx'; my ($user) = "user"; my ($pass) = "password"; my $ppk_filepath = 'private_file.ppk' my $ssh2

我一直在尝试使用perl连接到sftp服务器,我尝试了几个模块和puTTy,但没有成功

use Net::SFTP::Foreign;
use Net::SFTP::Foreign::Backend::Net_SSH2;
use Net::SSH2;

my ($host) = 'xxx.xxxx.xxx';
my ($user) = "user";
my ($pass) = "password"; 
my $ppk_filepath = 'private_file.ppk'

my $ssh2 = Net::SSH2->new();
$ssh2->connect($host) or die "connect failed";
$ssh2->debug(1);
$ssh2->auth_publickey($user, undef, $ppk_filepath, $pass) or $ssh2-> die_with_error;
my $sftp = Net::SFTP::Foreign->new(ssh2 => $ssh2, backend => 'Net_SSH2');
$sftp->error and die "Unable to stablish SFTP connection: ". $sftp->error;`
我通常会遇到这样的错误:

无法从私钥文件提取公钥:密码短语错误或私钥文件格式无效/无法识别(-16 LIBSSH2\u ERROR\u file)


我会做错什么呢?在perl中,是否有另一种通过sftp连接的方式,使用私钥、用户名和密码作为身份验证?提前感谢

钥匙是PuTTY格式的(
*.ppk
)。您希望它采用OpenSSH的格式(
id\u rsa
)。通过加载
.ppk
文件并从“转换”菜单中选择“导出OpenSSH密钥”,可以使用进行转换。

密钥采用PuTTY格式(
*.ppk
)。您希望它采用OpenSSH的格式(
id\u rsa
)。通过加载
.ppk
文件并从“转换”菜单中选择“导出OpenSSH密钥”,使用来转换它