curl-library
Problem with right data to file using WWW::Curl
Date: Mon, 21 Jun 2004 10:39:34 -0700
Hi. I'm trying to download a file using the WWW::Curl::easy perl
module. I receive the data but it never gets written to my file. Any
help would be appreciated. Here's my code:
#!/usr/bin/perl
use strict;
no strict 'subs';
use WWW::Curl::easy;
use IO::File;
my $url = "ftp://nebulous.cobaltgroup.com/NOTES";
my $body="";
sub chunk { my ($data,$pointer)=@_; ${$pointer}.=$data; return length($data) }
#init curl session
my $curl = WWW::Curl::easy->new();
my $code = $curl->setopt(CURLOPT_TIMEOUT, 30);
$code = $curl->setopt(CURLOPT_URL, $url);
my $fh = new IO::File("test2.txt", 'w');
$code = $curl->setopt(CURLOPT_WRITEFUNCTION, \&chunk );
$code = $curl->setopt(CURLOPT_FILE_,\$fh);
print "MY CODE: [$code]";
$curl->perform();
my $bytes=$curl->getinfo(CURLINFO_SIZE_DOWNLOAD);
print" bytes: $bytes\n";
Received on 2004-06-21