I was running into problems trying to get the zip file to download. I was getting the prompt to download, but the file was coming up empty. The problem I was running into was that the connection to the browser is a stateless connection, and lost the credentials that was being used in getting the file in the first step.
Had to save the file locally to a temp directory and create a direct link, (files are deleted after 24 hours) allowing people to download the file directly.
This is what I ended up doing:
$filename = 'test.zip';
# get file from external ftp
use LWP::UserAgent;
use HTTP::Request::Common;
my $url = "http://www.domain.com/$filename";
my $ua = LWP::UserAgent->new(keep_alive=>1);
my $headers = HTTP::Headers->new();
$headers->authorization_basic('user', 'pass');
my $request = new HTTP::Request(GET => $url, $headers);
my $response = $ua->request($request);
print "response:" . $response->code . "<br>";
# save file locally
$filepath = "e:/myfolder/Data/$filename";
open(ZIP, ">$filepath");
binmode ZIP;
print ZIP $response->content;
close(ZIP);
# provide link to download file
print "Download file <a href="http://www.localftp.com/Data/$filename">
+here</a>";
Don't think there was a solution to downloading the file via the a prompt.
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.