我一直在尝试使用 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;`
Run Code Online (Sandbox Code Playgroud)
我通常会收到此错误:
Unable to extract public key from private key file: Wrong passphrase or invalid/unrecognized private key file format (-16 LIBSSH2_ERROR_FILE)
我做错了什么?,还有另一种方法可以通过 sftp 使用 perl 中的私钥、用户名和密码作为身份验证进行连接吗?提前致谢