cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: libcurl (perl) FTP download using wildcards

From: Cris Bailiff <c.bailiff+curl_at_devsecure.com>
Date: Fri, 9 May 2003 15:25:20 +1000

(Follow ups sent to the curl-library list...)

On Fri, 9 May 2003 04:03 am, Miguel Laborde wrote:

> 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):

...script snipped....

Your script looks OK to me - no obvious errors.

> ------- OUT PUT

...snipped...

This looks like a typical libcurl/ftp prologue. OK so far...

> 227 Entering Passive Mode (216,12,212,200,224,167).
> * About to connect() to rezox.com:57511
> * Connecting to 216.12.212.200 (216.12.212.200) port 57511
> * Connected the data stream with PASV!
>
> > TYPE A
>
> 200 Type set to A.
>
> > LIST
>
> 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
>
> <SNIPPED THE DIRECTORY LISTING THAT CURL AUTOMATICALLY PRODUCES>

I think you mean that the listing is produced by the 'print join('',@body)'
command in your script. (Does it go away if you comment this line?) This
would prove that, actually, libcurl did do the ftp listing data transfer (and
it was captured and put into the input array). The error must be caused by
'something else'.

> 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?

Sorry, no real idea here. It would probably help (Daniel at least) if you
could specify which libcurl (and Curl::easy) versions you are using, and
possibly the platform.

I don't think this is anything perl specific. Can you reproduce this problem
with the 'curl' command line? For what it's worth, I see a similar error
trying to get a listing from 1 public ftp site, but not another (with curl
7.10.4):

curl -l ftp://ftp.planetmirror.com/
raid
pub
welcome.msg
curl: (56) Connection aborted

curl -l ftp://mirror.aarnet.edu.au/
pub
raid
debian
debian-non-US

Why it should be ftp server dependant, I can't say, but perhaps you could test
your script against another server?

Aside, I noted (with -v) that curl uses NLST for an ftp listing when running
'curl -l'. Perhaps you should do the same? Or, possibly, POSTQUOTE is not the
right way to ask libcurl for a listing - perhaps libcurl wasn't expecting a
data connection at the right time?

Cris

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