develooper Front page | perl.beginners | Postings from April 2023

Re: help with making an sftp connection

Thread Previous | Thread Next
From:
Brent Wood via beginners
Date:
April 17, 2023 23:53
Subject:
Re: help with making an sftp connection
Message ID:
375836203.5190422.1681775615601@mail.yahoo.com
 Thanks for that suggestion, it does provide more info, and using the script more as you formatted it:
say "start";

$sftp = Net::SFTP::Foreign->new($host,
    user => $user,
    password => $pass,
    more => [
        qw(
             -v 
             -o PreferredAuthentications=password 
             -o PasswordAuthentication=yes 
             -o BatchMode=yes
         )
    ]
    );say "done";

 
I get this output:
start
...debug1: Local version string SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.9p1 Ubuntu-3ubuntu0.1
debug1: compat_banner: match: OpenSSH_8.9p1 Ubuntu-3ubuntu0.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 127.0.0.1:22 as 'baw'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:9xuiSKoLyBrR6XdL2Ktv9Osdoq257n++/zUO0izC+7s
Host key verification failed.
done

It seems to be trying to use key based authentication irrespective of the -o parameters passed in. I looked for an ssh based fix & found this: https://superuser.com/questions/1376201/how-do-i-force-ssh-to-use-password-instead-of-key
Which suggested the issue was possibly at the server end, but my /etc/ssh/ssh_config file is set up to allow password authentication, and I can ssh in directly with password only, so it does not seem that this is my problem. 

As far as I can tell, it is just scripted sftp via Perl that seems to fail. Even if I omit the user & password entries in the connect string, Perl still gets my user as the default & never prompts for a password, just gives the same message. It may be worth trying to do this with Net::SFTP instead of Net::SFTP::Foreign, any advice?


Thanks again,
Brent





    On Monday, April 17, 2023 at 10:58:49 PM GMT+12, Dermot <paikkos@gmail.com> wrote:  
 
 Hi,
Can you edit the constructor to include `more => [ -v ]` so we can get more feedback from the SSH connection and send the output from that. 

$sftp = Net::SFTP::Foreign->new($host,
        user     => $user,
        password => $pass,
        more => [
            qw(
            -v
            -o PreferredAuthentications=password
            -o PasswordAuthentication=yes
            -o BatchMode=yes
            )
       ]
)  or $sftp->error;

The clue to what is going wrong will be in the output from ssh.Thanks,Dermot

On Mon, 17 Apr 2023 at 10:13, Brent Wood via beginners <beginners@perl.org> wrote:

 More detail, thanks for your time...

This is to test the Perl script on a local (Linux) system, copying a file from /tmp to another directory.

I can use command line sftp to copy a file fine with the user/password connection, so there is not a problem with sftp, user/password etc on the system.

This Perl script executes without error, but hangs on $sftp = Net::... (prints start, never prints done) 

If I take out the password assignment, I'm prompted for a password and it then works fine. With it there, it hangs. 

Can anyone help me get this working with a password passed as a parameter?

use Net::SFTP::Foreign;
use IO::Pty;
use feature say;

$host = "127.0.0.1";
$user = "baw";
$pass = "......";

say "start";

$sftp = Net::SFTP::Foreign->new($host,
                    user => $user,
                    password => $pass,
                        more => [qw(-o PreferredAuthentications=password -o PasswordAuthentication=yes -o BatchMode=yes)]
    );

say "done";


  
Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About