Hi everyone,

I have looked around for a solution to this, but I cannot seem to find anything about it.

I would like to know if it is possible to read a file, over FTP (this is a must), line-by-line. The Net::FTP package will allow me to "get" entire files, and the "read" function does not appear to have a parameter for a file. There are other packages, like File::Remote, which allow line-by-line reading of remote files, but do not support FTP.

The problem that I am trying to solve is this. I have a very large list of files (indexed by company and year). Each company and year combination has multiple files associated with it. However, I know that I only want one of these files; I just can't tell which one from the listing. In order to tell if a particular file is the correct one, I need to read the header of the file (the files are .txt, but have HTML information in them which includes a header).

I would like to write a script which iterates over each filename in the list and retrieves each one from the FTP server one line at a time. I can then check each line to see if it contains the header information that I need, and I can exit the read if it does. Alternately, if line-by-line is not doable, I could extract a fixed number of lines from each file: the header does not always contain the same number of lines, but I could pick a threshold which would work.

These files are individually quite large, so I only want to download the ones that I need. Otherwise, I would download all the files and delete the ones that did not match.

Any help would be appreciated!

Matt


In reply to Read part of a file over FTP by ronin78

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.