简体   繁体   中英

Perl Net::SFTP::Foreign issue with password authentication

I am trying to transfer files to a remote host using perl Net::SFTP::Foreign. But I am gettting following error message through $sftp->error, while establishing the connection. This program is working fine for other remote hosts.

Error Message: Password not requested as expected: 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.

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

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 .

I have updated my sftp->new statement to have password_prompt in the args list, and it fixed my issue!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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