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

When trying to connect through Net::SFTP or Net::SFTP::Foreign in a mod perl env the connection gets borked. When I use a regular cgi perl interpretor it works like a charm.

the error that Net::SFTP::Foreign gives is:
Put error: Connection to remote server stalled
Put status: Connection lost


debug output is:
penSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Connecting to ftp.*******.com [***.*****.*****.****] port 22. debug1: Connection established. debug1: identity file /home/apache/.ssh/identity type -1 debug1: identity file /home/apache/.ssh/id_rsa type 1 debug1: identity file /home/apache/.ssh/id_dsa type -1 debug1: Remote protocol version 2.0, remote software version VShell_2_ +5_1_219 VShell debug1: no match: VShell_2_5_1_219 VShell 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 'ftp.****.com' is known and matches the DSA host key. debug1: Found key in /home/apache/.ssh/known_hosts2:1 DSA host key for IP address '*****' not in list of known hosts. debug1: ssh_dss_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: Authentication succeeded (password). debug1: channel 0: new [client-session] debug1: Entering interactive session. debug1: Sending environment. debug1: Sending env LANG = C debug1: Sending subsystem: sftp debug1: channel 0: free: client-session, nchannels 1 debug1: fd 0 clearing O_NONBLOCK debug1: fd 1 clearing O_NONBLOCK debug1: fd 2 clearing O_NONBLOCK debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.1 seconds debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0 debug1: Exit status -1

Using Net::SFTP I get the same results as:
problem with net::sftp

My sys admins have assured me that the server I am testing on is vanilla and all modules are up to date.

Sorry if I missed something in my searches. Any help would be appreciated, thank you.

Replies are listed 'Best First'.
Re: Net::SFTP::Foreign mod perl
by perrin (Chancellor) on May 21, 2009 at 17:47 UTC
    You're probably running as a different user and possibly don't have the right permissions to read/write some files that it needs.

      I might agree with that, except that the file I am trying to upload is using permissions of 755, and the script will work from the command line as the apache user, or really any of the users on that box. Does apache under mod perl have a different user other than the other perl interpretor? On our server we call it 'apache'. And the mod perl and cgi perl interpretors both use the same httpd.conf file. This really is a configuration of mod perl type question, so maybe this isn't the best form here.

      I do thank you for the suggestion, and maybe there is something that I am missing in the httpd.conf. What information might I provide to track this down?

        The user depends on how you configure it, but usually CGI programs don't run as the same user that apache runs as. Another potential difference is environment variables.
Re: Net::SFTP::Foreign mod perl
by salva (Canon) on May 21, 2009 at 21:13 UTC
    Set...
    $Net::SFTP::Foreign::debug = -1;
    to see what the module is doing and post the output here!

    Tracing the process at the OS level (with truss, strace, ktrace or similar), would also help.

      OpenSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Connecting to ftp.****.com [***.***.***.***] port 22. debug1: Connection established. debug1: identity file /home/apache/.ssh/identity type -1 debug1: identity file /home/apache/.ssh/id_rsa type 1 debug1: identity file /home/apache/.ssh/id_dsa type -1 debug1: Remote protocol version 2.0, remote software version VShell_2_ +5_1_219 VShell debug1: no match: VShell_2_5_1_219 VShell 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 'ftp.*****.com' is known and matches the DSA host key. debug1: Found key in /home/apache/.ssh/known_hosts2:1 DSA host key for IP address '***.***.***.***' not in list of known hos +ts. debug1: ssh_dss_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: password,publickey,gssapi-w +ith-mic debug1: Next authentication method: gssapi-with-mic debug1: An invalid name was supplied Unknown code krb5 243 debug1: An invalid name was supplied Unknown code krb5 243 debug1: An invalid name was supplied Unknown code krb5 243 debug1: Next authentication method: publickey debug1: Trying private key: /home/apache/.ssh/identity debug1: Offering public key: /home/apache/.ssh/id_rsa debug1: Authentications that can continue: password,publickey,gssapi-w +ith-mic debug1: Trying private key: /home/apache/.ssh/id_dsa debug1: Next authentication method: password #13647 queueing msg len: 5, code:1, id:3 ... [1] 00 00 00 05 01 00 00 00 03 + | ......... #13647 waiting for message... [1] #13647 _do_io connected: 1 #13647 _do_io select(-,-,-, undef) #13647 _do_io write queue: 9, syswrite: undef, max: 20480 #13647 _conn_lost #13647 _set_status code: 7, str: Connection lost #13647 _set_err code: 37, str: Connection to remote server is broken #13647 _conn_lost ####################### Connected ####################### #13647 queueing msg len: 10, code:11, id:0 ... [2] 00 00 00 0a 0b 00 00 00 00 00 00 00 01 2e + | .............. #13647 waiting for message... [2] #13647 _do_io connected: 0 #13647 _conn_lost #13647 new remote dir '.' open, rid: #13647 queueing msg len: 29, code:3, id:1 ... [3] 00 00 00 1d 03 00 00 00 01 00 00 00 08 66 69 6c 65 2e 74 78 74 00 00 0 +0 1a 00 00 00 04 00 00 01 | .............file.txt........... a4 + | . #13647 waiting for message... [3] #13647 _do_io connected: 0 #13647 _conn_lost #13647 _set_status code: 7, str: Connection lost #13647 _set_err code: 37, str: Connection to remote server stalled #13647 new remote file 'file.txt' open, rid: ####################### Successful ####################### #13647 Net::SFTP::Foreign=HASH(0x55557f9b8e30)->DESTROY called (curren +t pid: 13647, disconnect_by_pid: ) #13647 Net::SFTP::Foreign=HASH(0x55557f9b8e30)->disconnect called (ssh + pid: 13655) #13647 _conn_lost debug1: Authentication succeeded (password). debug1: channel 0: new [client-session] debug1: Entering interactive session. debug1: Sending environment. debug1: Sending env LANG = C debug1: Sending subsystem: sftp debug1: channel 0: free: client-session, nchannels 1 debug1: fd 0 clearing O_NONBLOCK debug1: fd 1 clearing O_NONBLOCK debug1: fd 2 clearing O_NONBLOCK debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.1 seconds debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0 debug1: Exit status -1
      Thank you!
        Something is going wrong on the password authentication process... it looks like ssh does not see the password until its /dev/tty stream is closed.

        Can you trace the script at the OS level with strace (or similar) to see the data being exchanged between the module and the ssh process? Ensure that the full data is dumped (i.e. strace -s 100000 ...).

        You may need to remove sensible information as passwords from the dump.

        Which module version, perl version and OS are you using?