我正在尝试使用 perl Net::SFTP::Foreign 将文件传输到远程主机。但在建立连接时,我通过 $sftp->error 收到以下错误消息。该程序对于其他远程主机运行良好。
错误消息: 未按预期请求密码:0
对应的代码片段:
my %args = (password => $config->[$i]->{'PSWD'}, user => $config->[$i]->{'USERNAME'}, port => $config->[$i]->{'PORT'}, more => [-o => 'StrictHostKeyChecking no'], more => '-v');
$sftp = Net::SFTP::Foreign->new($config->[$i]->{'HOSTNAME'}, %args);
详细日志(相关部分):
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: keyboard-interactive,password
debug1: Next authentication method: keyboard-interactive
Password authentication
此后,程序因上述错误而终止。
最佳答案
根据我的个人经验,Net::SFTP::Foreign 的工作方式会根据您要连接的服务器的设置而有所不同。
以下是我建议您尝试的步骤:
尝试通过硬编码主机、用户、密码、端口(默认为 22,或任何实际端口)进行连接:
my %args = (user => "username", password => "password", port => 22, more => [-o => 'StrictHostKeyChecking no']);
如果这不起作用,请尝试以下操作:
my %args = (user => "username", password => "password", port => 22, more => [-o => 'StrictHostKeyChecking no', -o => 'PreferredAuthentications=password']);
my %args = (user => "username", password => "password", port => 22, more => [-o => 'StrictHostKeyChecking no', -o => 'PreferredAuthentications=password,keyboard-interactive']);
my %args = (user => "username", password => "password", port => 22, more => [-o => 'StrictHostKeyChecking no', -o => 'PreferredAuthentications=keyboard-interactive,password']);
一旦这些连接字符串之一起作用,请尝试用变量替换硬编码值。
关于Perl Net::SFTP::Foreign 密码验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39095211/