cURL / Mailing Lists / curl-library / Single Mail

curl-library

CURLOPT_POSTQUOTE chmod uploaded file

From: Bryan Hansen <bhansen_at_ubermind.com>
Date: Thu, 20 Sep 2007 17:03:02 -0700

Hello,

I am trying to upload a file to an ftp server using the libcurl
framework in a cocoa app. I would like to chmod the file after
uploading, but I am having trouble with CURLOPT_POSTQUOTE. It is
giving me a curl error code 21, implying this error on the remote
server:

When sending custom "QUOTE" commands to the remote server, one of the
commands returned an error code that was 400 or higher.

I'm wondering if I am calling the CURLOPT_POSTQUOTE incorrectly, or
if it could somehow have something to do with the current directory
curl is set to at the point in time the POSTQUOTE is run. I have
tried with various forms of the path and just the filename alone, but
I always am getting back this same error.

Any insight will be much appreciated! Thanks,
Bryan

CURL *curlHandle = curl_easy_init();
if (curlHandle)
{
     // get a handle to the file to upload
     FILE *localPathFile = fopen([localPath cString],"rb");

     NSURL *uploadURL = [NSURL URLWithString:@"ftp://
msmith:pass_at_localhost:21/%2F/Users/msmith/pic.jpg"]];

     // set proxy settings
     [self _setFTPProxyForCURL:curlHandle];

     NSString *filePath = @"/Users/msmith/pic.jpg";

     struct curl_slist *headerlist = NULL;
     headerlist = curl_slist_append(headerlist, [[NSString
stringWithFormat:@"SITE CHMOD 664 %@",filePath] cString]);
     curl_easy_setopt(curlHandle, CURLOPT_POSTQUOTE, headerlist);

     curl_easy_setopt(curlHandle, CURLOPT_URL,[[uploadURL
absoluteString] cString]);

     // tell curl to keep track of progress
     curl_easy_setopt(curlHandle, CURLOPT_NOPROGRESS, FALSE);
     curl_easy_setopt(curlHandle, CURLOPT_PROGRESSFUNCTION,
curlProgressFunction);
     curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA, self);

     // enable uploading
     curl_easy_setopt(curlHandle, CURLOPT_UPLOAD,TRUE);

     // specify file to upload
     curl_easy_setopt(curlHandle, CURLOPT_READDATA, localPathFile);

     CURLcode curlCode = curl_easy_perform(curlHandle);
}
Received on 2007-09-21