Hi Shlomi,
Here is a working example. I tried it on Linux and it works. After many try
and error changes. I found that adding a use Net:SSL (); fixes the problem.
Which I think means the default IO::Socket::SSL does not (if Net:SSL exists
too). Is that possible ?
Markus
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use File::Basename;
# use Net:SSL ();
sub writelog {
my ($msg, $priority, $dummy, $stack_index) = @_;
# swapout any carriage returns in error message:
$msg =~ s|\n| |g;
$stack_index ||= 0;
print uc($priority) . "$msg\n";
return;
} # end sub _writelog
sub log_and_die {
my ( $msg, $priority, $dummy ) = @_;
# get calling function details (one up the stack):
writelog($msg, "crit: ", "", 1);
die $msg;
}
# utility function to transfer a file via GET or PUT to
sub http_transfer {
my ( $url, $file, $method, $site_details ) = @_;
die "Need url and dest_file as params" unless @_ > 1;
# set the method:
$method ||= "get";
# set the url:
$url ||= _url_from_site_details($site_details);
log_and_die("I need a URL!") unless ($url);
writelog("Try to [$method] [$url]");
# skip certification verification:
my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 });
my $response;
# only needed for gets:
# create the dest file dir unless it already exists:
my $file_dir ||= dirname($file);
unless ( -d $file_dir ) {
writelog "$file_dir doesn't exist - will create now.";
make_path $file_dir ;
}
# set content_file for output, and send the request:
$response = $ua->get($url, ':content_file' => $file );
if ( $response->is_error ) {
log_and_die( "[" . $response->status_line . "] error trying to
$method $url.");
} else {
writelog( "[" . $response->status_line . "] for $method transfer to
$url.");
}
} # end sub _http_transfer
http_transfer( "https://test.com/file " , "download.tmp");
"Shlomi Fish" <shlo...@shlomifish.org> wrote in message
news:20120927110442.28e0f...@lap.shlomifish.org...
Hello Markus,
On Sun, 23 Sep 2012 00:19:38 +0100
"Markus Moeller" <hua...@moeller.plus.com> wrote:
Hi,
I have a problem that my perl modules are not anymore downloading a
large file from a https site. It worked with a previoius built, but
since I update all modules via cpan it fails after downloading some
parts.
I use the following code:
sub http_transfer {
my ( $url, $file ) = @_;
die "Need url and dest_file as params" unless @_ > 1;
# set the method:
$method ||= "get";
log_and_die("I need a URL!") unless ($url);
# skip certification verification:
my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname =>
0 }); my $response;
if ( $method eq "get" ) {
my $file_dir ||= dirname($file);
unless ( -d $file_dir ) {
make_path $file_dir ;
}
# set content_file for output, and send the request:
$response = $ua->get($url, ':content_file' => $file );
}
if ( $response->is_error ) {
log_and_die( "[" . $response->status_line . "] error trying
to $method $url.");
}
} # end sub _http_transfer
Your code is not self-contained, and is strange and suffers from bad idioms.
Can you please provide a self-contained, reproducing, example that
all of us can run?
The platform I run on is Solaris 10 and perl , openssl is compiled
with SUNWspro cc.
Ouch!
Do you know if the same code is working fine on an up-to-date Linux
distribution?
Regards,
Shlomi Fish
Any idea how to debug ? When I use truss I see my old perl modules
just read until the end whereas the new modules for some reason get a
read = 0 somewhere at the beginning of the file download.
Thank you
Markus
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
My Public Domain Photos - http://www.flickr.com/photos/shlomif/
Real programmers don’t write workarounds. They tell their users to upgrade
their software.
Please reply to list if it's a mailing list post - http://shlom.in/reply .