in reply to Read part of a file over FTP

This uses Net::FTP to fetch the first two hundred bytes of a 180k file:

#! perl -slw use strict; use Net::FTP; my $ftp = Net::FTP->new( 'ftp.software.ibm.com' ); $ftp->login( 'anonymous', 'anonymous@' ); $ftp->cwd( '/ftp' ); $ftp->ascii; my $xfr = $ftp->retr( '00_Catalog' ); my $buf; $xfr->read( $buf, 200 ); print $buf;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Read part of a file over FTP
by ronin78 (Novice) on May 27, 2011 at 19:29 UTC

    Yes, this is what I wanted! Thanks very much!

    As a follow up question, the buffer now returns the first file in my loop, and I get the text that I want, but fails on the second with the error: Can't call method "read" on an undefined value. However, I have verified that the new filename is correct, so I assume that there must be some problem with reinitializing the dataconn object?

    Is there a recommended way to clear a retr() so that a new one can be called? Or is that not even likely to be my problem?

    Relevant code is below: The while loop is on a MySQL query return. Note that I haven't done anything with the buffer yet.
    while (@results = $filequery->fetchrow()) { $filename="/".$filename; print "$filename\n"; $xfr = $ftp->retr($filename); $xfr->read($header,1400); print "$header\n"; }
      Note, for the above code, that I have tried the following things to close the retr():
      $ftp->close(); $xfr->close();
      But no joy. I'm just stabbing in the dark, though, so that's not really surprising.

        Use $xfr->abort; to abort the retr, and $ftp->quit to close the connection.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        Fantastic! Sorry if my questions are noobish, and thanks very much for the help.

        Matt