Subject: | Connection hangs for certain servers when password is incorrect |
I found a server that is not compatible with the '-o
NumberOfPasswordPrompts=1' option that Net::SFTP::Foreign passes on to
sftp:
$ sftp -o NumberOfPasswordPrompts=1 user@___.com
Connecting to ___...
This System Is For Authorized Users Only.
Password Authentication
Password: (wrong password)
user@___.com's password:
Normally, with this option, sftp will disconnect after a single bad
password attempt. This server sends a second, slightly different,
password request. Net::SFTP::Foreign doesn't know what to do with the
second password request, and it hangs.
My quick fix was to add an extra line feed when the password is sent
initially (line 314 of Foreign/Backup/Unix.pm in version 1.73).
print $pty "$pass\n\n";
If the password is incorrect, the extra line feed gets us past the
second password prompt. If the login is correct, it posts a harmless
linefeed to the sftp interface. This is a hack, but I figured I would
mess things up if I did another sysread from $pty.