http://qs321.pair.com?node_id=1233380


in reply to SFTP connection failure with Perl “Net::SFTP” module

Hello Michaels,

I would suggest to comment out the identity_files and also password. Simply do this:

#!/usr/bin/perl use strict; use warnings; use Net::SFTP; my $host = '127.0.0.1'; my %args = ( user => 'user', ssh_args => [ port => "10022" ] ); my $sftp = Net::SFTP->new($host, %args); my $ls = $sftp->ls('/sample/path'); print "$_->{filename}\n" for (@$ls);

I would also suggest to use the module Net::SFTP::Foreign. You can find more information as to why on a previoudly asked question Re: Using Net::SFTP.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: SFTP connection failure with Perl “Net::SFTP” module
by Michaels (Novice) on May 06, 2019 at 08:34 UTC
    Thank you thanos1983! But how can I point to the private key file if I'll remove 'identity_files'? BR, Michael

      Hello Michaels,

      If you do not use default path of you SSH keys then you can use the option identity_files but you need to remove the password.

      Let me know if it works for you.

      BR / Thanos

      Seeking for Perl wisdom...on the process of learning...not there...yet!
        Hi thanos, I removed the password as you suggested but it still trying to login with password before using the private key:
        my %args = ( user => "$user", port => "$port", key_path => 'path/sftp_download', ssh_args => { user => "$user", identity_files => [ 'path/sftp_download'], port => "$port", protocol=>'2,1', debug => 1, } ); my $sftp=Net::SFTP->new($server, %args) or die "could not open connect +ion to $server\n";