简体   繁体   English

Perl Net :: SFTP ::带密码验证的外部问题

[英]Perl Net::SFTP::Foreign issue with password authentication

I am trying to transfer files to a remote host using perl Net::SFTP::Foreign. 我正在尝试使用perl Net :: SFTP :: Foreign将文件传输到远程主机。 But I am gettting following error message through $sftp->error, while establishing the connection. 但是我在建立连接时通过$ sftp-> error得到了错误消息。 This program is working fine for other remote hosts. 此程序适用于其他远程主机。

Error Message: Password not requested as expected: 0 错误消息: 未按预期请求密码:0

Corresponding code fragment: 对应的代码片段:

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);

Verbose log (Relevant piece): 详细日志(相关部分):

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

After this, program gets terminated with the error mentioned above. 在此之后,程序因上述错误而终止。

From my personal experience, Net::SFTP::Foreign works differently based on the setup of the server you are connecting to. 根据我的个人经验,Net :: SFTP :: Foreign的工作方式与您连接的服务器的设置不同。

Here are the steps I suggest you to try: 以下是我建议您尝试的步骤:

Try to connect by hardcoding host, user, password, port (22 is default, or whatever the actual port is): 尝试通过硬编码主机,用户,密码,端口(默认情况下为22,或实际端口为)进行连接:

my %args = (user => "username", password => "password", port => 22, more => [-o => 'StrictHostKeyChecking no']);

If that does not work, try the following: 如果这不起作用,请尝试以下操作:

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']);

Once one of these connection strings work, try to replace hardcoded values with your variables. 一旦这些连接字符串中的一个工作,尝试用您的变量替换硬编码值。

I appreciate the support provided by everyone. 我感谢大家提供的支持。 I was able to figure the issue at last. 我终于能够解决这个问题了。 Listing below my findings and solution for reference! 列出我的发现和解决方案以供参考!

Issue was with the password prompt from the remote host, it was not in the expected format. 问题是来自远程主机的密码提示,它不是预期的格式。 You can find the reference over here (look up for password_prompt ): http://search.cpan.org/~salva/Net-SFTP-Foreign-1.86/lib/Net/SFTP/Foreign.pm . 你可以在这里找到引用(查找password_prompt): http//search.cpan.org/~salva/Net-SFTP-Foreign-1.86/lib/Net/SFTP/Foreign.pm

I have updated my sftp->new statement to have password_prompt in the args list, and it fixed my issue! 我更新了我的sftp-> new语句,在args列表中有了password_prompt,它解决了我的问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM