Hi Monks,
I have a script that's using LWP to do very simple FTP gets and puts. The code for the FTP GET looks something like this:
#an FTP get
my $ua;
$ua = LWP::UserAgent->new();
$ua->agent("$0/0.1 ".$ua->agent);
my $req = HTTP::Request->new(GET => "$url");
my $result = $ua->request($req);
And the code for an FTP PUT looks something like this:
#an FTP put
#open the file and read the contents
my $content;
if (open DATA_READER, "$data_file") {
$content = join ("", <DATA_READER>);
close DATA_READER;
} else {
warn "UNABLE TO READ $data_file, upload will be empty! $!\n";
}
my $ua;
$ua = LWP::UserAgent->new();
$ua->agent("$0/0.1 ".$ua->agent);
my $req = HTTP::Request->new('PUT',"$url",undef,"$content");
my $result = $ua->request($req);
The thing is, I really don't care about the file data itself--in fact, when I do the ftp get, I never actually write the file to disk; I'm just concerned about whether the file was transfered properly or not. Some of the files I have to fetch and put are rather large...around 100-250MB. With the above method, perl is taking up a huge chunk of memory to buffer the files. Can anyone suggest a way to reduce the memory footprint of this code? For instance, is there a way to feed the file to the FTP put without buffering it into memory first? Likewise, is there a way to flush the buffer in the FTP get as data is coming in? It would be best if I can do this with LWP instead of having to resort to using other modules.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.