chipchidster has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone, i'm currently trying to write an ftp'ing program in perl and am having real trouble using the stfp modules to make an sftp connection using password authentication. I've read through the various threads here at the monastery, but none seem to hit the mark. Thus i post the question.

So, i have played around with using the following:

  • Net::SFTP::Foreign (yes i know it's being depricated)
  • Net::SFTP::Foreign::Compat
  • Net::SFTP

    I can make a connection with all of them, but with the first two i get the following in my log:

    debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-keyex,gssa +pi-with-mic,password debug1: Next authentication method: password debug1: read_passphrase: can't open /dev/tty: No such device or addres +s debug1: Authentications that can continue: publickey,gssapi-keyex,gssa +pi-with-mic,password Permission denied, please try again. debug1: read_passphrase: can't open /dev/tty: No such device or addres +s debug1: Authentications that can continue: publickey,gssapi-keyex,gssa +pi-with-mic,password Permission denied, please try again. debug1: read_passphrase: can't open /dev/tty: No such device or addres +s debug1: Authentications that can continue: publickey,gssapi-keyex,gssa +pi-with-mic,password debug1: No more authentication methods to try. Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). reading from ssh pipe failed ()

    Running Net::SFTP seems to work, but i would much rather make use of the installed SSH2 system modules, rather than the Perl implementation of the same.

    From my relatively poor understanding of how this all works, i understand that the login process is trying to write a response back to the calling process, and as it is essentially a batch process no tty device is available i get the error. However, from what i understand, installing IO::Pty should stop this problem - but it doesn't.

    I am running this on CentOS rel 5.5 with all the latest patches. Perl v5.8.8 and all the latest module versions are installed. Does anyone have any suggestions, because i am all out of ideas.

  • Replies are listed 'Best First'.
    Re: SFTP login problems
    by roboticus (Chancellor) on May 03, 2012 at 10:34 UTC

      chipchidster:

      I've not used any of those modules, but the error messages you listed indicate that the SSH system needs a user ID/password and can't get it. Since the Net::SFTP::Foreign module's new method accepts the user ID and password, perhaps it would work if you pass your credentials in at that time. If you'd rather not use the password authentication method, maybe you can configure it to *not* try to use it, as that's where it's failing for you.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

    Re: SFTP login problems
    by salva (Canon) on May 03, 2012 at 11:00 UTC
      Net::SFTP::Foreign (yes i know it's being depricated)

      Before replying to your question let me clarify that Net::SFTP::Foreign is NOT being deprecated!!!

      Now, can you show us your script, otherwise it is difficult to know what you are doing wrong.

      Also, activate Net::SFTP::Foreign debugging inserting the following line at the beginning of your script:

      $Net::SFTP::Foreign::debug = -1;
      And post here the output you get when you run it after that.

        Yes, sorry - schoolboy error not to have posted the script code. So, amendments made to add the debug flag, the offending call is:

        # use the STEP param specified SFTP port printlog( "Opening an SFTP connection to $FTPaddress at port($SFTP +PORT)"); $ftp = Net::SFTP::Foreign->new($FTPaddress, user => $FTPuser, password => $FTPpasswd, port => $SFTPPORT, debug => $debug, more => [qw(-v -o PreferredAuth +entications=password)]

        The output of the log is:

        20120503 12:23:50 Step [50]: The old API for Net::SFTP::Foreign inherited from Net::SFTP is being o +bsoleted. Use Net::SFTP::Foreign::Compat for a package offering a mos +tly compatible API or upgrade to the development version of this pack +age and use the new and much improved API. at ********.pl line 252 20120503 12:23:51 SFTP: Will attempt to send (0) files to customer(man +age02.bds.tv) as user(proadmin), 20120503 12:23:51 SFTP: Opening an SFTP connection to ******** at port +(22) sftp: Sending SSH2_FXP_INIT OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Connecting to ******** [*******] port 22. debug1: Connection established. debug1: identity file /home/probatch/.ssh/identity type -1 debug1: identity file /home/probatch/.ssh/id_rsa type 1 debug1: identity file /home/probatch/.ssh/id_dsa type 2 debug1: loaded 3 keys debug1: Remote protocol version 2.0, remote software version OpenSSH_5 +.3 debug1: match: OpenSSH_5.3 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_4.3 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-cbc hmac-md5 none debug1: kex: client->server aes128-cbc hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug1: Host '********' is known and matches the RSA host key. debug1: Found key in /home/probatch/.ssh/known_hosts:33 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-keyex,gssa +pi-with-mic,password debug1: Next authentication method: password debug1: read_passphrase: can't open /dev/tty: No such device or addres +s debug1: Authentications that can continue: publickey,gssapi-keyex,gssa +pi-with-mic,password Permission denied, please try again. debug1: read_passphrase: can't open /dev/tty: No such device or addres +s debug1: Authentications that can continue: publickey,gssapi-keyex,gssa +pi-with-mic,password Permission denied, please try again. debug1: read_passphrase: can't open /dev/tty: No such device or addres +s debug1: Authentications that can continue: publickey,gssapi-keyex,gssa +pi-with-mic,password debug1: No more authentication methods to try. Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). reading from ssh pipe failed () at *****.pl line 252 20120503 12:23:51 Step [50] complete.

        As you can see from the warning at the top - that is why i assumed that Net::SFTP::Foreign was being depricated

          Whoa, you are using a version of Net::SFTP::Foreign on the 0.xx series that I stopped maintaining six years ago!!!

          Just install a recent version of the module.

    Re: SFTP login problems
    by zentara (Cardinal) on May 03, 2012 at 10:38 UTC