cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problems creating a directory tree with FTP

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 1 Aug 2002 10:16:49 +0200 (MET DST)

On Wed, 31 Jul 2002, Gerard Cheng wrote:

> I am trying to find a way to create a directory tree on a remote FTP site
> if it does not already exist. But I am running into problems with FTP and
> was hoping there is an easier way to handle this with libCurl.
>
> I want to create a directory tree from the root FTP directory
> of the form:
> a/b/c
>
> Since FTP doesn't seem to have an equivalent to "mkdir -p", I am using
> CURLOPT_QUOTE to send a series of FTP commands like this:
> MKD a
> MKD a/b
> MKD a/b/c
>
> However, if any of the subdirectories already exists, the
> curl_easy_perform() fails with error "CURLE_FTP_QUOTE_ERROR" and does not
> try to FTP the file.
>
> I thought I could test if the subdirectory already exists by trying to CWD
> to it, but then I have no way of conditionally calling the MKD if this
> fails. Does anyone know of a way to get around this problem?

Right.

libcurl has no good interface for sending custom commands to an ftp server
with conditions such as you describe above.

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

 Check first path part:

   curl ftp://server.com/a/

 if it failed, create it:

   curl -Q "MKD a" -Q "MKD a/b" -Q "MKD a/b/c" ftp://server.com
   *done*

 else it worked, check next part:

   curl ftp://server.com/a/b/

 etc...

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?

-- 
 Daniel Stenberg -- curl related mails on curl related mailing lists please
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2002-08-01