in reply to Re^2: LWP Credentials Login Problem to Download Zip Files
in thread LWP Credentials Login Problem to Download Zip Files

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.