cURL / Mailing Lists / curl-library / Single Mail

curl-library

Still can't write to file in perl..need help =(

From: Swati Vakharia <swativ_at_gmail.com>
Date: Mon, 21 Jun 2004 17:09:55 -0700

ok..so from my other posts im slowly figuring this out..but i still
cant get the data that i read from the ftp server to be written to a
file. If I pass CURLOPT_FILE a normal variable, the data is stored
into that file. But if i pass CURLOPT_FILE a file handle, nothing is
getting printed. Any help would be appreciated! =) Here's what I have
so far...

#!/usr/bin/perl

use strict;
no strict 'subs';
use WWW::Curl::easy;
$| = 1;
use IO::File;

my $url = "ftp://ftp.mysite.com/tables/babfutxt.txt";
my $body;

sub write {
    my ( $data, $pointer ) = @_;
    ${$pointer} .= $data;
    return length($data);
}

my $fh = new IO::File( "babfutxt.txt", 'w' ) or die " cannot create
new file $!";

#init curl session
my $curl = WWW::Curl::easy->new();

my $code = $curl->setopt( CURLOPT_USERPWD, "dfsd:fdsf" );
$code = $curl->setopt( CURLOPT_TIMEOUT, 30 );

$code = $curl->setopt( CURLOPT_WRITEFUNCTION, \&write );
$code = $curl->setopt( CURLOPT_FILE, \$fh);
$code = $curl->setopt( CURLOPT_URL, $url );
$code = $curl->setopt( CURLOPT_FTP_USE_EPSV, 0 );
$code = $curl->setopt( CURLOPT_FTP_SSL, 1 );

$code = $curl->perform();
my $bytes = $curl->getinfo(CURLINFO_SIZE_DOWNLOAD);
print " code: $code\n";
print " bytes: $bytes\n";

$fh->close();
Received on 2004-06-22