I think the problem is in the way that you try to parse the ftp "dir" output -- you have this:
my @files=$ftp->dir or print FD1 "error in dir list..." ... foreach(@files) { ... $_=substr($_,41); ... }
There's no guarantee that each line of output from "dir" will have the file name starting at the 41st character. If the file size (which is the fourth column in the dir output) happens to be really large (more than 7 digits, I think), then that column will be wider than on other lines, and the file name will be pushed that many characters further to the right.

Use "split()" instead -- the number of columns output by "dir" is always the same:

my @files = $ftp->dir or die "ack -- can't get ftp->dir"; for ( @files ) { my ($mode, $nlnk, $grp, $sz, $mo, $dy, $yrtm, $fname) = split( /\s+ +/, $_, 8 ); ... }
This let's you have a variable assigned to every piece of information you could possibly use (and some that you will probably never use) -- and you don't need "chomp" here.

Note the use of the "8" in the split call -- this will make sure that we stop splitting at the 8th "word", so if some jerk puts up a file with spaces in the file name, split() will still treat the whole name as one "word" to be assigned to $fname.


In reply to Re: Bad file descriptor' error with automated FTP script. by graff
in thread Bad file descriptor' error with automated FTP script. by Anonymous Monk

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.