cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Problems creating a directory tree with FTP

From: Gerard Cheng <cheng_at_vertigoxmedia.com>
Date: Thu, 1 Aug 2002 16:45:48 -0400

> The only working way I can come up with off the top of my head is to
attempt
> to list the directory and if that fails, you try to create it. Using curl
> commands, something like this (we want to create a/b/c) :
>
> [SNIP]

I am using libCurl so to imitate your code snippet I needed to make a series
of calls to curl_easy_perform() with:
        CURLOPT_NOBODY=true
        CURLOPT_HEADER=false
so that no FTP transfer occurs. In each, I tested CWD for each subdirectory
of the tree using a QUOTE. For example:
        CWD a
If the return is CURLE_FTP_QUOTE_ERROR, I append a QUOTE to the actual file
transfer command to call MKD on that directory:
        MKD a

Repeat this for a/b, a/b/c and so on. Then the actual file transfer will
create any subdirectories required.

However, with libcurl version 7.9.7 I found that in my testing loop when
there should be no transfer, I *intermittantly* get the error
CURLE_FTP_COULDNT_STOR_FILE? Why should it be trying to store a file? With
verbose debugging on, I get:

* About to connect() to ********:********@phoenix1:21
* Connected to phoenix1.******** (192.168.1.176) port 21
> USER ********
> PASS ********
* We have successfully logged in
> PWD
* Entry path is '/c:/ftp'
> CWD image
> CWD ..
> TYPE I
> STOR (nil)
* Connection #0 left intact
* Re-using existing connection! (#0)
* Connected to [re-used] (192.168.1.176) port 21
> CWD image/master
> CWD ..
> CWD ..
> CWD /c:/ftp
> TYPE I
> STOR (nil)

and the error buffer said:
        Failed FTP upload: Try later - data connection in use

Am I using something incorrectly? I see that a file called "(nil)" is
created temporarily on the FTP site but is removed when the packet times out
and aborts.

> I am interested in improving this situation so that operations such as
these
> would be easier to implement. Do you have any ideas or suggestions on how
> this would work to make it easiest possible for you?

For me, a CURLOPT similar to the -p option for mkdir would serve as a nice
interface:
        curl_easy_setopt(m_curlHandle, CURLOPT_CREATE_DIRTREE, TRUE);

With this option set, libCurl could do a loop prior to the file transfer
similar to the one I describe above to test for existance of subdirectories
and would add MKD commands as required.

However, this algorithm may not fit in well with libCurl since it
effectively needs to do a number of "command only" transfers to look for
subdirectories before the actual file transfer. I don't know if this
interface would be appropriate for other protocols either.

Thanks for your help!

G

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2002-08-02