cURL / Mailing Lists / curl-library / Single Mail

curl-library

Using CURLOPT_FTP_CREATE_MISSING_DIRS

From: <Don_Marino_at_May-Co.com>
Date: Thu, 30 Sep 2004 11:46:20 -0400

I have set this option using curl_easy_setopt but it does not appear to be
doing what I think it ought to do. I think it ought to create the
directory if it does not exist. I am trying to get a file to the
following
directory structure on a redhat linux system: /home/ps/isp.

I have successfully transferred the file when the directory structure
already exists. The following is what shows up when debug is turned on:

        <= Recv header, 52 bytes (0x34)
        0000: 220 wps013 FTP server (Version wu-2.6.2-12) ready.
        => Send header, 9 bytes (0x9)
        0000: USER ps
        <= Recv header, 31 bytes (0x1f)
        0000: 331 Password required for ps.
        => Send header, 14 bytes (0xe)
        0000: PASS psadmin
        <= Recv header, 24 bytes (0x18)
        0000: 230 User ps logged in.
        => Send header, 5 bytes (0x5)
        0000: PWD
        <= Recv header, 38 bytes (0x26)
        0000: 257 "/home/ps" is current directory.
        => Send header, 9 bytes (0x9)
        0000: CWD isp
        <= Recv header, 29 bytes (0x1d)
        0000: 250 CWD command successful.
        => Send header, 6 bytes (0x6)
        0000: EPSV
        <= Recv header, 48 bytes (0x30)
        0000: 229 Entering Extended Passive Mode (|||50184|)
        => Send header, 8 bytes (0x8)
        0000: TYPE I
        <= Recv header, 20 bytes (0x14)
        0000: 200 Type set to I.
        => Send header, 17 bytes (0x11)
        0000: STOR skn100.zip
        <= Recv header, 57 bytes (0x39)
        0000: 150 Opening BINARY mode data connection for skn100.zip.
        => Send data, 178 bytes (0xb2)
        0000:
PK........JD;1..j.....'.......skn100.datUT.....XA..XAUx....&.3.1
        0040: .BC
......1..rAL....r..PK..........JD;1..j.....'................
        0080: .....skn100.datUT.....XAUx..PK..........E...W.....
        <= Recv header, 24 bytes (0x18)
        0000: 226 Transfer complete.

I have tried transferring a file to the following url
ftp://rps180.gldc/isp/skn100.zip when the directory isp does not exist.
The following is what I get when debug is turned on:

        <= Recv header, 52 bytes (0x34)
        0000: 220 wps013 FTP server (Version wu-2.6.2-12) ready.
        => Send header, 9 bytes (0x9)
        0000: USER ps
        <= Recv header, 31 bytes (0x1f)
        0000: 331 Password required for ps.
        => Send header, 14 bytes (0xe)
        0000: PASS psadmin
        <= Recv header, 24 bytes (0x18)
        0000: 230 User ps logged in.
        => Send header, 5 bytes (0x5)
        0000: PWD
        <= Recv header, 38 bytes (0x26)
        0000: 257 "/home/ps" is current directory.
        => Send header, 9 bytes (0x9)
        0000: CWD isp
        <= Recv header, 37 bytes (0x25)
        0000: 550 isp: No such file or directory.

This is where libcurl itself attempts to change to the directory where the
file should reside.

I have also tried transferring the file to the following url
ftp://rps180.gldc/skn100.zip when the directory isp does not exist. I
also send a header to explicitly do a CWD to /isp. The following is what
debug shows:

        <= Recv header, 52 bytes (0x34)
        0000: 220 wps013 FTP server (Version wu-2.6.2-12) ready.
        => Send header, 9 bytes (0x9)
        0000: USER ps
        <= Recv header, 31 bytes (0x1f)
        0000: 331 Password required for ps.
        => Send header, 14 bytes (0xe)
        0000: PASS psadmin
        <= Recv header, 24 bytes (0x18)
        0000: 230 User ps logged in.
        => Send header, 5 bytes (0x5)
        0000: PWD
        <= Recv header, 38 bytes (0x26)
        0000: 257 "/home/ps" is current directory.
        => Send header, 10 bytes (0xa)
        0000: CWD /isp
        <= Recv header, 38 bytes (0x26)
        0000: 550 /isp: No such file or directory.

I'm not sure what I am doing wrong. Following is a snippet of the code:

        curl_global_init(CURL_GLOBAL_DEFAULT);
 
           curl = curl_easy_init();
 
           if (curl)
              {
              if ( (fp = fopen( pcLocalFile,
                                "r" )) == NULL )
                 {
           return( 1 );
                 } // end if ((fp = fopen()) == NULL)
 
              curl_easy_setopt( curl,
                                CURLOPT_ERRORBUFFER,
                                pcErrorText );

              curl_easy_setopt( curl,
                          CURLOPT_FTP_CREATE_MISSING_DIRS,
                            lMissingDirs );

              if ( sDebugLvl > 0 )
                 {
                 // Open debug info file
                 if ( (config.fpDebugFile = fopen(
"/home/ps/debuginfo/debuginfo.txt",
                                            "a" )) == NULL )
                    {
                    return( 1 );
                    } // end if ((fp = fopen()) == NULL)

                 // Enable verbose info if testing/debugging (DISABLE IN
PRODUCTION)
           curl_easy_setopt( curl,
                               CURLOPT_VERBOSE,
                                 TRUE );

                 if ( sDebugLvl > 1 )
              {
                config.trace_ascii = 1; // enable ascii tracing
 
                      // Enable my debug function called my_trace
              curl_easy_setopt( curl,
                                  CURLOPT_DEBUGFUNCTION,
                                    my_trace );
 
                    // Set pointer to my data to pass into the debug
function(my_trace)
                curl_easy_setopt( curl,
                                    CURLOPT_DEBUGDATA,
                                      &config );
                    } // end if (sDebugLvl > 1)
           else
                // Enable debug info to be written to a file(DISABLE IN
PRODUCTION)
                    curl_easy_setopt( curl,
                                CURLOPT_STDERR,
                                  config.fpDebugFile );
                 } // end if (DebugLvl > 0)
 
        // Build a list of header commands to pass to libcurl that will be

              // executed before the transfer

              for( sHeaderIndex = 0; sHeaderIndex < sNumOfHeaders;
sHeaderIndex++ )
           headerlist = curl_slist_append( headerlist,
                                             &pcHeaders[sHeaderIndex] );
 
 
              // Enable upload(ftpput)
              curl_easy_setopt( curl,
                          CURLOPT_UPLOAD,
                            TRUE );

              // Set Destination file
        curl_easy_setopt( curl,
                                CURLOPT_URL,
                          url );
 
              // Set userid and password
              curl_easy_setopt( curl,
                          CURLOPT_USERPWD,
                                userid_password );
 
                // Pass in the Header commands
              curl_easy_setopt( curl,
                          CURLOPT_QUOTE,
                            headerlist );
 
              // Set file to upload(ftpput)
        curl_easy_setopt( curl,
                            CURLOPT_INFILE,
                              fp );
 
              // Set the size of the file to upload(ftpput)
        curl_easy_setopt( curl,
                            CURLOPT_INFILESIZE,
                              FileSize );
 
              // Execute upload(ftpput)
        res = curl_easy_perform(curl);

Any help or leads that you could give me would be greatly appreciated.

Thanks.
Received on 2004-09-30