Haxx ad

curl's project page on


cURL > Mailing List > Monthly Index > Single Mail

curl-users Mailing List Archives

libcurl (perl) FTP download using wildcards

From: Miguel Laborde <>
Date: Thu, 8 May 2003 14:03:02 -0400

Hello all,

        I've just started working with libcurl on perl today and I'm having some difficulties. Right now I have to write a script that will connect to an ftp server and to download files. After much playing I've realized that one specifies either the directory to cd into, or the file to download by setting that with the CURLOPT_URL option. My problem is this, I wish to specify a wildcard, *, when referencing the files to download as I don't know ahead of time what the names are.

        So what I've tried doing is to set the CURLOPT_URL just to the directory that the files will be located in and then using the CURLOPT_POSTQUOTE options I'm trying to get a diretory listing of the files in there, but this is failing. Here is a copy of my script (Login and password are hidden):

        use strict;
use Curl::easy;
use Data::Dumper;

use constant DEBUG => 1;

# Variables
my @body;
my $address = '';
my $login = '****'
my $password = '****

# Init the curl session
my $curl= Curl::easy->new() or die "curl init failed!\n";

# Verbose debugging
$curl->setopt(CURLOPT_VERBOSE, 1) if(DEBUG);

# Set curl parameters
$curl->setopt(CURLOPT_URL, $address);
$curl->setopt(CURLOPT_USERPWD, $login.':'.$password);
$curl->setopt(CURLOPT_FTP_USE_EPSV, 0);
open ERRFH, ">err.txt" && $curl->setopt(CURLOPT_STDERR, *ERRFH);

sub body_callback {
    my ($chunk,$context)=@_;
    push @{$context}, $chunk;
    return length($chunk); # OK
$curl->setopt(CURLOPT_WRITEFUNCTION, \&body_callback);
$curl->setopt(CURLOPT_FILE, \@body);
$curl->setopt(CURLOPT_STDERR, *ERRFH);

my @commands = 'LIST';
$curl->setopt(CURLOPT_POSTQUOTE, \@commands);

print join("", @body);

------- OUT PUT

* About to connect() to
* Connected to ( port 21
220 ProFTPD 1.2.4 Server (FTPd) []
> USER ****
331 Password required for ****.
> PASS ****
230 User **** logged in.
* We have successfully logged in
257 "/" is current directory.
* Entry path is '/'
> CWD carlos
250 CWD command successful.
227 Entering Passive Mode (216,12,212,200,224,167).
* About to connect() to
* Connecting to ( port 57511
* Connected the data stream with PASV!
200 Type set to A.
150 Opening ASCII mode data connection for file list
* Getting file with size: -1
226 Transfer complete.
> list
425 Can't build data connection: Connection refused
* QUOT string not accepted: list
* Connection #0 left intact


So I'm getting an error when I try and do a directory listing... In fact I'm getting an error with anything that requires me opening up a data stream.. ANy idea what I'm doing wrong?

                Thanks! :)

Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
Received on 2003-05-08

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET