It seems the Net::FTP::Recursive object is having trouble with closing the ftp connection. That said, as it seems to be about to do a listing of directories, I'm not sure why it would closing it without giving the output of the listing.

I run my script, which errors out at line 54 in one of the module files:

[root@host6 dell-download]# ./get-files.pl > out.log 2>&1 & [1] 10027 [root@host6 dell-download]# tail -f out.log Net::FTP::Recursive=GLOB(0x1c109a8)>>> CDUP Net::FTP::Recursive=GLOB(0x1c109a8)<<< 250 CDUP command successful. Net::FTP::Recursive=GLOB(0x1c109a8)>>> CWD Red Hat Enterprise Linux 4. +7 Net::FTP::Recursive=GLOB(0x1c109a8)<<< 250 CWD command successful. Making dir: Red Hat Enterprise Linux 4.7 Calling rget in /Browse_For_Drivers/Servers, Storage & Networking/Powe +rEdge/PowerEdge R610/Network/HTML Net::FTP::Recursive=GLOB(0x1c109a8)>>> PASV Net::FTP::Recursive=GLOB(0x1c109a8)<<< 227 Entering Passive Mode (143, +166,135,12,206,55) Net::FTP::Recursive=GLOB(0x1c109a8)>>> LIST Can't use an undefined value as a symbol reference at /usr/share/perl5 +/Net/FTP/dataconn.pm line 54. ^C [1]+ Exit 255 ./get-files.pl > out.log 2>&1
I can ftp to the server manually and get a listing just fine:
ftp> cd "Browse_For_Drivers/Servers, Storage & Networking/PowerEdge/Po +werEdge R610/Network/HTML" 250 CWD command successful. ftp> ls 227 Entering Passive Mode (143,166,135,12,221,177) 125 Data connection already open; Transfer starting. drwxrwxrwx 1 owner group 0 Aug 29 2012 Linux drwxrwxrwx 1 owner group 0 Aug 29 2012 LINUX - OS ..<listings removed>.. drwxrwxrwx 1 owner group 0 Aug 29 2012 Windows Ser +ver 2008 x86 226 Transfer complete.
I open /usr/share/perl5/Net/FTP/dataconn.pm, which shows (line numbers also shown):
48 sub _close { 49 my $data = shift; 50 my $ftp = ${*$data}{'net_ftp_cmd'}; 51 52 $data->SUPER::close(); 53 54 delete ${*$ftp}{'net_ftp_dataconn'} 55 if exists ${*$ftp}{'net_ftp_dataconn'} 56 && $data == ${*$ftp}{'net_ftp_dataconn'}; 57 }
This _close function is called here:
60 sub close { 61 my $data = shift; 62 my $ftp = ${*$data}{'net_ftp_cmd'}; 63 64 if (exists ${*$data}{'net_ftp_bytesread'} && !${*$data}{'net +_ftp_eof'}) { 65 my $junk; 66 $data->read($junk, 1, 0); 67 return $data->abort unless ${*$data}{'net_ftp_eof'}; 68 } 69 70 $data->_close;
I checked with our network admin, who said the inactivity timeout is one hour, i.e. if there is no data being sent in a 1 hour period, the firewall will close the connection. I'd think there's probably something similar on the ftp server side as well. However, I can't see, from the debug output above, why a long period of inactivity would happen. As I mentioned, it seemed like it was about to do a directory listing, then got cut off.

Below is the code in question. While I'm creating my own directory structure, I'm creating an ftp connection for each directory and changing directories each time, so I don't see why this should be causing this problem.

#!/usr/bin/perl use strict; use warnings; use Carp; use Data::Dumper; use Net::hostent; #use Net::Ping; use Net::FTP::Recursive; use Log::StdLog { level => 'info', file => $0 . "log" }; #use Log::StdLog { level => 'warn', file => $config{log}{file} . $0 . +"log" }; my %params = ( site => "ftp.dell.com", basedir => "Browse_For_Drivers/Servers, Storage & Networking/Power +Edge", modeldirs => [ "PowerEdge R810", "PowerEdge R610", "PowerEdge R720", "PowerEdge R620", "PowerEdge M620", "PowerEdge M1000E", ], ); print {*STDLOG} info => "Starting $0, creating dirs."; for my $dir (@{ $params{modeldirs}}) { mkdir $dir; chdir $dir; FTPConnect (\%params, "$dir"); chdir ".."; } print {*STDLOG} info => "Finished $0."; sub FTPConnect { my $ref_params = shift @_; my $dir = shift @_; my $ftp = Net::FTP::Recursive->new($ref_params->{site}, Debug => 1 +, Timeout => 15); if ($ftp) { print {*STDLOG} debug => "OK: connected via FTP to " . $ref_p +arams->{site} ; $ftp->login("anonymous",'me@here.there'); $ftp->binary; $ftp->cwd($ref_params->{basedir} . '/' . $dir); print {*STDLOG} info => "Starting download for dir $dir.\n"; $ftp->rget( #FlattenTree => 1, MatchFiles => qr/\.txt$/, ); print {*STDLOG} info => "Finished download for dir $dir.\n"; $ftp->quit; } else { print {*STDLOG} warn => "ERROR: FTP for host $ref_params->{site}\n +" } return ; } sub GetFiles { return; }
Any thoughts on why the connection dying? It's happened a number of times already.

-- Burvil


In reply to Net::FTP::Recursive problems, prematurely closing connection by bowei_99

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.