Hi What is your password_prompt on your remote sftp server? ex: root@192.168.56.100's password:
according the document, your script will hang at the login phase if the wrong prompt is used. Brent Wood via beginners <beginners@perl.org> 於 2023年4月18日 週二 上午7:54寫道: > 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.1debug1: Remote protocol version 2.0, remote software > version OpenSSH_8.9p1 Ubuntu-3ubuntu0.1debug1: compat_banner: match: > OpenSSH_8.9p1 Ubuntu-3ubuntu0.1 pat OpenSSH* compat 0x04000000debug1: > Authenticating to 127.0.0.1:22 <http://127.0.0.1:22> as 'baw'debug1: > SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug1: kex: > algorithm: curve25519-sha256debug1: kex: host key algorithm: > ssh-ed25519debug1: kex: server->client cipher: > chacha20-poly1...@openssh.com <chacha20-poly1...@openssh.com> MAC: > <implicit> compression: nonedebug1: kex: client->server cipher: > chacha20-poly1...@openssh.com <chacha20-poly1...@openssh.com> MAC: > <implicit> compression: nonedebug1: expecting > SSH2_MSG_KEX_ECDH_REPLYdebug1: SSH2_MSG_KEX_ECDH_REPLY receiveddebug1: > Server host key: ssh-ed25519 > SHA256:9xuiSKoLyBrR6XdL2Ktv9Osdoq257n++/zUO0izC+7sHost 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 <paik...@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"; > >