0

I use $ftp = Net::SFTP::Foreign->new(%args); to sftp to Linux machine from HP-UX. It works with no problems.

When I try to connect to an SFTP server installed on Windows, it does not work $ftp->error contains Connection to remote server is broken error and login procedure timed out when with more => '-v' option.

When I run it with more => '-vvv' I get below log. Can anyone help me understand the issue and help fixing it?

debug1: Host 'windowsHost' is known and matches the RSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:3
debug2: bits set: 4101/8192
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: input_userauth_banner
Welcome! Please login.
debug1: Authentications that can continue: password,publickey,keyboard-interactive
debug3: start over, passed a different list password,publickey,keyboard-interactive
debug3: preferred keyboard-interactive,password
debug3: authmethod_lookup keyboard-interactive
debug3: remaining preferred: password
debug3: authmethod_is_enabled keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug2: input_userauth_info_req
password
Enter password for user
debug2: input_userauth_info_req: num_prompts 1
debug1: Authentications that can continue: password,publickey,keyboard-interactive
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: 
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug3: packet_send2: adding 64 (len 55 padlen 9 extra_pad 64)
debug2: we sent a password packet, wait for reply
debug1: Authentications that can continue: password,publickey,keyboard-interactive
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (password,publickey,keyboard-interactive).

Please, notice that it works for linux hosts

(Per request from comments) Trying to connect to via SSH to the SFTP server from unix. I don't believe it is supposed to work and it doesn't...

unixServerName ENV:/home/me/scripts/perl=>ssh user\@windowsHost
password
Enter password for user
Password:
shell request failed on channel 0
unixServerName ENV:/home/me/scripts/perl=>

Now using SFTP from command line

unixServerName ENV:/home/me/scripts/perl=>sftp user\@windowsHost
password
Enter password for user
Password:
Connected to windowsHost.
sftp>
sftp> quit
unixServerName ENV:/home/me/scripts/perl=>
Alex
  • 1,054
  • 6
  • 25
  • 42
  • This seems relevant: `read_passphrase: can't open /dev/tty: No such device or address` – choroba Nov 19 '16 at 00:27
  • How come it doesn't cause problems when I connect to Linux hosts? – Alex Nov 19 '16 at 00:28
  • How do you connect to the Linux host? Do you use a password, passphrase to a key, passphraseless key, ...? Can you connect to the Windows server via some other tool? – choroba Nov 19 '16 at 00:29
  • password. I can connect to Windows server from command line using sftp command, as well as using WinScp from my desktop – Alex Nov 19 '16 at 00:31
  • 1
    *"Please, notice that it works for linux hosts"* But you have tagged your question "unix" and "hp-ux". Your question mentions Windows too. Please tidy the tags and explain clearly which source and destination systems work, and which don't. – Borodin Nov 19 '16 at 03:12
  • The Windows server may be using a custom password prompt not recognized by Net::SFTP::Foreign. See [password_prompt](https://metacpan.org/pod/Net::SFTP::Foreign#password_prompt-regex_or_str) – salva Nov 19 '16 at 19:06
  • @salva. I get an error "Invalid option 'password_prompt' or bad combination" for $ftp = Net::SFTP::Foreign->new(host => 'myHost', port => 22, user => 'myUserId', password => 'myPassword', password_prompt => qr/\bpassword>\s*$/); – Alex Nov 21 '16 at 19:51
  • perl -MCPAN -e 'print "$CPAN::VERSION\n"' returns 2.10 – Alex Nov 21 '16 at 19:56
  • password_prompt is not the issue. I tried with different account and it works for that account. I suspect that the issue could be caused by special characters in the password – Alex Nov 21 '16 at 20:14
  • Could you log manually into that machine using `ssh` from the command line and add to your post above a capture of the full interaction? Also, which version of Net::SFTP::Foreign are you using? – salva Nov 22 '16 at 07:52
  • Version of Net::SFTP::Foreign is '1.71'. Other requested info I added in the question description – Alex Nov 24 '16 at 18:46

1 Answers1

1

The issue was caused by ('#') pound sign character in the password. Super strange. I was able to reproduce the issue on servers from 2 different vendors. So for sure this is a bug in Net::SFTP::Foreign

Notice that this happens only on Windows hosts and works fine for Unix HP and Linux Hosts.

To make my argument a little bit stronger, from command line SSH and SFTP everything works.

Alex
  • 1,054
  • 6
  • 25
  • 42
  • 1
    oh, that's a [known issue](https://metacpan.org/pod/Net::SFTP::Foreign#Password-authentication-on-HP-UX) on HP-UX. So far, nobody has been able to explain why it happens! – salva Nov 25 '16 at 10:00