Paul Corr on Sun, 8 Jul 2001 23:41:24 -0400 |
Folks, In recent days, I've experienced an odd problem with a Net::FTP script. I have a script that uses Net::FTP to pick up between 95 and 300 small files. Often, the script will run successfully without complaint, getting all the files. But occasionally, it generates many complaints to the screen and stops getting files at the point that the complaints begin. It appears to lose the ftp connection. Here's an example of the error from my notes: --- Can't get '_tb_bc-hungryrabbits(2).htm': Bad file descriptor at process_krtfeed.pl line 402. Syswrite on closed filehandle at /usr/local/lib/perl5/site_perl/5.005/i386-freebsd/Net/Cmd.pm line 172. Use of uninitialized value at /usr/local/lib/perl5/site_perl/5.005/i386-freebsd/Net/Cmd.pm line 172. --- After guessing that the parens in the file name might cause trouble, I modify the code to skip such files, but the behavior continued. As I said, the behavior is intermittent. I'm wondering if anyone has any best practices tips for maintaining or checking the ftp connection. I'm wondering if maybe I should add something more than 'warn' to check the connection in the 'ftp->get' line in the script below. Any feedback is appreciated. Paul ---- -------- Here's the (excerpted) code: #--- # set some script variables and values my $now = time(); # non-leap seconds since epoch my $age = 86400 * 1; # '1' for one day, etc. # x 60 * 60 * 24 secs/day # connect to ftp server containing feed files $ftp = Net::FTP->new($host,debug => 1); $rc = $ftp->login($user,$pass); # open connection die "Unable to establish a connection $!" unless $rc; @allfiles = list_all_files(); get_todays_files(@allfiles); # sub checks date, retrieves files $ftp->quit; # close connection exit(0); sub list_all_files { @ftpfiles = $ftp->ls("*.htm"); foreach my $file (@ftpfiles){ push(@skippedfiles,$file) and next if( $file =~ m|\(\d+\)\.htm| ); push(@goodfiles,$file); } return @goodfiles; } sub get_todays_files { # get files from ftp site my @curfiles = @_; # all files passed in return unless(scalar @curfiles); # return if no files my @todaysfiles; foreach my $file (@curfiles){ next unless( $ftp->size($file) > 300 ); # min size next unless( ($now - $ftp->mdtm($file) ) < $age ); push (@todaysfiles,$file); } foreach my $file (@todaysfiles){ $ftp->get($file) or warn "Can't get '$file': $!" and next; sleep 1; # pause seconds between 'gets' $retrieved++; } } #--- **Majordomo list services provided by PANIX <URL:http://www.panix.com>** **To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
|
|