[Ssh-sftp-perl-users] Help with Net::SFTP using mod_perl
Brought to you by:
dbrobins
From: Isaac M. <IM...@pr...> - 2009-05-07 23:03:56
|
Hi there, Thanks in advance. I have a simple perl script that uses the Net::SFTP module. All it has to do is put a file on a remote server. This script works fine from my command line, but it fails from a mod_perl handled web page. Is there some ENV value that needs to be defined? Vitals: kernel: 2.6.18-92.1.22 (CentOS 5.2 - RHEL clone, x86_64) perl: 5.8.8 perl-Net-SSH: 0.08 perl-Net-SFTP: 0.10 Apache: 2.2.3 mod_perl: 2.0.4 Here's the script: -----code snippet----- #!/usr/bin/perl -w use strict; use Net::SFTP; use Net::SSH::Perl; $ENV{'DOCUMENT_ROOT'} = '/var/www/html'; $ENV{'HOME'} = '/home/apache'; $ENV{'USER'} = 'apache'; my $host = "ftp.some-remote-host.com"; my %args = (user => "myUserName", password => "myPassword", ssh_args => [port=>22], debug => "true"); my $sftp = Net::SFTP->new($host, %args) or die "Cannot connect to $@"; print "Successfully Connected.\n"; $sftp->put("localfile.txt", "remotefile.txt"); print "Success.\n"; exit(0); -----end code snippet----- Here's the output that demonstrates the script working as the user "apache" from the command line (the uid that also runs httpd/apache): -----output snippet----- im.corp.local: Reading configuration data /home/apache/.ssh/config im.corp.local: Reading configuration data /etc/ssh_config im.corp.local: Connecting to ftp.some-remote-host.com, port 22. im.corp.local: Remote version string: SSH-2.0-VShell_2_5_1_219 VShell im.corp.local: Remote protocol version 2.0, remote software version VShell_2_5_1_219 VShell im.corp.local: Net::SSH::Perl Version 1.30, protocol version 2.0. .m.corp.local: No compat match: VShell_2_5_1_219 VShell im.corp.local: Connection established. im.corp.local: Sent key-exchange init (KEXINIT), wait response. im.corp.local: Algorithms, c->s: 3des-cbc hmac-sha1 none im.corp.local: Algorithms, s->c: 3des-cbc hmac-sha1 none im.corp.local: Entering Diffie-Hellman Group 1 key exchange. im.corp.local: Sent DH public key, waiting for reply. im.corp.local: Received host key, type 'ssh-dss'. im.corp.local: Host 'ftp.some-remote-host.com' is known and matches the host key. im.corp.local: Computing shared secret key. im.corp.local: Verifying server signature. im.corp.local: Waiting for NEWKEYS message. im.corp.local: Enabling incoming encryption/MAC/compression. im.corp.local: Send NEWKEYS, enable outgoing encryption/MAC/compression. im.corp.local: Sending request for user-authentication service. im.corp.local: Service accepted: ssh-userauth. im.corp.local: Trying empty user-authentication request. im.corp.local: Authentication methods that can continue: password,publickey,gssapi-with-mic. im.corp.local: Next method to try is password. im.corp.local: Trying password authentication. im.corp.local: Login completed, opening dummy shell channel. im.corp.local: channel 0: new [client-session] im.corp.local: Requesting channel_open for channel 0. im.corp.local: channel 0: open confirm rwindow 32768 rmax 16384 im.corp.local: channel 1: new [client-session] im.corp.local: Requesting channel_open for channel 1. im.corp.local: Sending subsystem: sftp im.corp.local: Requesting service subsystem on channel 1. im.corp.local: channel 1: open confirm rwindow 32768 rmax 16384 im.corp.local: sftp: Sending SSH2_FXP_INIT im.corp.local: sftp: Remote version: 3 Connected. im.corp.local: sftp: Sent SSH2_FXP_OPEN I:0 P:file.txt im.corp.local: sftp: Sent message SSH2_FXP_WRITE I:1 O:0 im.corp.local: sftp: In write loop, got 252 offset 0 im.corp.local: sftp: Sent message T:10 I:2 im.corp.local: sftp: Sent message T:4 I:3 -----end output snippet----- Here's the output from the script run under mod_perl when it fails - hangs up at the SSH2_FXP_INIT and times out: -----output snippet----- im.corp.local: Reading configuration data /home/apache/.ssh/config im.corp.local: Reading configuration data /etc/ssh_config im.corp.local: Connecting to ftp.some-remote-host.com, port 22. im.corp.local: Remote version string: SSH-2.0-VShell_2_5_1_219 VShell im.corp.local: Remote protocol version 2.0, remote software version VShell_2_5_1_219 VShell im.corp.local: Net::SSH::Perl Version 1.30, protocol version 2.0. .m.corp.local: No compat match: VShell_2_5_1_219 VShell im.corp.local: Connection established. im.corp.local: Sent key-exchange init (KEXINIT), wait response. im.corp.local: Algorithms, c->s: 3des-cbc hmac-sha1 none im.corp.local: Algorithms, s->c: 3des-cbc hmac-sha1 none im.corp.local: Entering Diffie-Hellman Group 1 key exchange. im.corp.local: Sent DH public key, waiting for reply. im.corp.local: Received host key, type 'ssh-dss'. im.corp.local: Host 'ftp.some-remote-host.com' is known and matches the host key. im.corp.local: Computing shared secret key. im.corp.local: Verifying server signature. im.corp.local: Waiting for NEWKEYS message. im.corp.local: Enabling incoming encryption/MAC/compression. im.corp.local: Send NEWKEYS, enable outgoing encryption/MAC/compression. im.corp.local: Sending request for user-authentication service. im.corp.local: Service accepted: ssh-userauth. im.corp.local: Trying empty user-authentication request. im.corp.local: Authentication methods that can continue: password,publickey,gssapi-with-mic. im.corp.local: Next method to try is password. im.corp.local: Trying password authentication. im.corp.local: Login completed, opening dummy shell channel. im.corp.local: channel 0: new [client-session] im.corp.local: Requesting channel_open for channel 0. im.corp.local: channel 0: open confirm rwindow 32768 rmax 16384 im.corp.local: channel 1: new [client-session] im.corp.local: Requesting channel_open for channel 1. im.corp.local: Sending subsystem: sftp im.corp.local: Requesting service subsystem on channel 1. im.corp.local: channel 1: open confirm rwindow 32768 rmax 16384 im.corp.local: sftp: Sending SSH2_FXP_INIT [Thu May 07 16:34:55 2009] [error] Received disconnect message: 12893: Server disconnect. Session idle time exceeded. \n at /usr/lib/perl5/vendor_perl/5.8.8/Net/SSH/Perl/SSH2.pm line 284\n -----end output snippet----- If I need to direct this to another list, could you enlighten me? I'll follow the mail list, so no need to private message me. Thanks for your help though, -Isaac This message (and any associated files) is intended only for the use of the individual or entity to which it is addressed and may contain information that is confidential, subject to copyright or constitutes a trade secret. If you are not the intended recipient you are hereby notified that any dissemination, copying or distribution of this message, or files associated with this message, is strictly prohibited. If you have received this message in error, please notify us immediately by replying to the message and deleting it from your computer. Messages sent to and from us may be monitored. Internet communications cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. Therefore, we do not accept responsibility for any errors or omissions that are present in this message, or any attachment, that have arisen as a result of e-mail transmission. If verification is required, please request a hard-copy version. Any views or opinions presented are solely those of the author and do not necessarily represent those of the company. |