Net::SFTP is dropping connection when my program invokes ls, but only when the program is run by cron or 'at now'. Here's an example that demonstrates:

#!/opt/local/perl/bin/perl -w use strict; use Net::SFTP; my $sftp = Net::SFTP->new("serverURL.com", user => "myUser", password => 'myPassword', debug => 1); my $targetDir = "/ftp/pub"; # connection dropped at this line when run from cron, but not from com +mand line my $lsHashRef = $sftp->ls($targetDir); map { my $filename = $_->{filename}; print "$filename\n"; } sort {$a->{filename} cmp $b->{filename}} @$lsHashRef; print "Done!\n";

The debug output from a successful command-line-invoked run:

lxdenvmap162: Reading configuration data /u/liveproc/.ssh/config lxdenvmap162: Reading configuration data /etc/ssh_config lxdenvmap162: Connecting to lxdenvmpc366.qintra.com, port 22. lxdenvmap162: Remote version string: SSH-2.0-OpenSSH_4.3 lxdenvmap162: Remote protocol version 2.0, remote software version Ope +nSSH_4.3 lxdenvmap162: Net::SSH::Perl Version 1.30, protocol version 2.0. lxdenvmap162: No compat match: OpenSSH_4.3. lxdenvmap162: Connection established. lxdenvmap162: Sent key-exchange init (KEXINIT), wait response. lxdenvmap162: Algorithms, c->s: 3des-cbc hmac-sha1 none lxdenvmap162: Algorithms, s->c: 3des-cbc hmac-sha1 none lxdenvmap162: Entering Diffie-Hellman Group 1 key exchange. lxdenvmap162: Sent DH public key, waiting for reply. lxdenvmap162: Received host key, type 'ssh-dss'. lxdenvmap162: Host 'lxdenvmpc366.qintra.com' is known and matches the +host key. lxdenvmap162: Computing shared secret key. lxdenvmap162: Verifying server signature. lxdenvmap162: Waiting for NEWKEYS message. lxdenvmap162: Enabling incoming encryption/MAC/compression. lxdenvmap162: Send NEWKEYS, enable outgoing encryption/MAC/compression +. lxdenvmap162: Sending request for user-authentication service. lxdenvmap162: Service accepted: ssh-userauth. lxdenvmap162: Trying empty user-authentication request. lxdenvmap162: Authentication methods that can continue: publickey,pass +word. lxdenvmap162: Next method to try is publickey. lxdenvmap162: Next method to try is password. lxdenvmap162: Trying password authentication. lxdenvmap162: Login completed, opening dummy shell channel. lxdenvmap162: channel 0: new [client-session] lxdenvmap162: Requesting channel_open for channel 0. lxdenvmap162: channel 0: open confirm rwindow 0 rmax 32768 lxdenvmap162: channel 1: new [client-session] lxdenvmap162: Requesting channel_open for channel 1. lxdenvmap162: Sending subsystem: sftp lxdenvmap162: Requesting service subsystem on channel 1. lxdenvmap162: channel 1: open confirm rwindow 0 rmax 32768 lxdenvmap162: sftp: Sending SSH2_FXP_INIT lxdenvmap162: sftp: Remote version: 3 lxdenvmap162: sftp: Sent message T:11 I:0 lxdenvmap162: sftp: Sent message T:12 I:1 lxdenvmap162: sftp: Received reply T:104 I:1 lxdenvmap162: sftp: Received 11 SSH2_FXP_NAME responses lxdenvmap162: sftp: Sent message T:12 I:2 lxdenvmap162: sftp: Received reply T:101 I:2 lxdenvmap162: sftp: Received SSH2_FXP_STATUS 1 lxdenvmap162: sftp: Sent message T:4 I:3 . .. XTRT.#CO.STRATA.RSKASAIF XTRT.#CO.STRATA.RSKASAIF.bkp XTRT.#EN.STRATA.RSKASAIF XTRT.#ES.STRATA.RSKASAIF XTRT.#NM.STRATA.RSKASAIF XTRT.#OR.STRATA.RSKASAIF XTRT.#UT.STRATA.RSKASAIF XTRT.#WA.STRATA.RSKASAIF processed Done!

The debug output from a failed run using 'at now' to run it:

lxdenvmap162: Reading configuration data /u/liveproc/.ssh/config lxdenvmap162: Reading configuration data /etc/ssh_config lxdenvmap162: Connecting to lxdenvmpc366.qintra.com, port 22. lxdenvmap162: Remote version string: SSH-2.0-OpenSSH_4.3 lxdenvmap162: Remote protocol version 2.0, remote software version Ope +nSSH_4.3 lxdenvmap162: Net::SSH::Perl Version 1.30, protocol version 2.0. lxdenvmap162: No compat match: OpenSSH_4.3. lxdenvmap162: Connection established. lxdenvmap162: Sent key-exchange init (KEXINIT), wait response. lxdenvmap162: Algorithms, c->s: 3des-cbc hmac-sha1 none lxdenvmap162: Algorithms, s->c: 3des-cbc hmac-sha1 none lxdenvmap162: Entering Diffie-Hellman Group 1 key exchange. lxdenvmap162: Sent DH public key, waiting for reply. lxdenvmap162: Received host key, type 'ssh-dss'. lxdenvmap162: Host 'lxdenvmpc366.qintra.com' is known and matches the +host key. lxdenvmap162: Computing shared secret key. lxdenvmap162: Verifying server signature. lxdenvmap162: Waiting for NEWKEYS message. lxdenvmap162: Enabling incoming encryption/MAC/compression. lxdenvmap162: Send NEWKEYS, enable outgoing encryption/MAC/compression +. lxdenvmap162: Sending request for user-authentication service. lxdenvmap162: Service accepted: ssh-userauth. lxdenvmap162: Trying empty user-authentication request. lxdenvmap162: Authentication methods that can continue: publickey,pass +word. lxdenvmap162: Next method to try is publickey. lxdenvmap162: Next method to try is password. lxdenvmap162: Trying password authentication. lxdenvmap162: Login completed, opening dummy shell channel. lxdenvmap162: channel 0: new [client-session] lxdenvmap162: Requesting channel_open for channel 0. lxdenvmap162: channel 0: open confirm rwindow 0 rmax 32768 lxdenvmap162: channel 1: new [client-session] lxdenvmap162: Requesting channel_open for channel 1. lxdenvmap162: Sending subsystem: sftp lxdenvmap162: Requesting service subsystem on channel 1. lxdenvmap162: channel 1: open confirm rwindow 0 rmax 32768 lxdenvmap162: sftp: Sending SSH2_FXP_INIT lxdenvmap162: sftp: Remote version: 3 lxdenvmap162: sftp: Sent message T:11 I:0 lxdenvmap162: channel 1: rcvd eof lxdenvmap162: channel 1: output open -> drain lxdenvmap162: channel 1: obuf empty lxdenvmap162: channel 1: output drain -> closed lxdenvmap162: channel 1: close_write lxdenvmap162: channel 1: rcvd close lxdenvmap162: channel 1: input open -> closed lxdenvmap162: channel 1: close_read lxdenvmap162: channel 1: send close lxdenvmap162: channel 1: full closed Connection closed at ./problem.pl line 13

I know this isn't likely to be Perl-specific, but please, oh mighty monks, do any of you have a guess about why this is happening?


In reply to Net::SFTP disconnect by gregor-e

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.