cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: SFTP delete file with space

From: Anders Havn <anders.havn_at_gmail.com>
Date: Fri, 18 May 2012 14:22:11 +0200

Hi again,

I solved the problem by adding quotation signs around the name and
encoding the full filePath:
NSString* fullFilePath = @"ftp://myftpserver.org/UserFolder/Test%20xyz.txt";
NSString* filePath = @"rm \"/UserFolder/Test xyz.txt\"";

Thank you.

Best Regards,
Anders Havn

On Thu, May 17, 2012 at 11:34 PM, Anders Havn <anders.havn_at_gmail.com> wrote:
> Hi,
>
> Thank you for your reply. I have tried encoding both the fullFillePath
> and the filePath, and it still doesn't work.
> NSString* fullFilePath = @"ftp://myftpserver.org/UserFolder/Test%20xyz.txt"
> NSString* filePath = @"rm /UserFolder/Test%20xyz.txt"
>
> In the output I can see this error message:
> "Kjkkaa* rm command failed: No such file or directory"
> "* Error"
>
>
> The same code works for normal ftp without any encoding in the paths:
> NSString username = @"username";
> NSString password = @"password";
> NSString* fullFilePath = @"ftp://myftpserver.org/UserFolder/Test
> xyz.txt"                                         <-- "ftp" instead of
> "sftp"
>
> NSString* filePath = @"DELE Test xyz.txt"
>                                                      <-- "DELE"
> instead of "rm" and only filename instead of file path from user
> folder
>  struct curl_slist* headerlist = curl_slist_append(NULL, [filePath
> cStringUsingEncoding:encoding]);
>
> curl_global_init(CURL_GLOBAL_DEFAULT);
> CURL *curl = curl_easy_init();
> curl_easy_setopt(curl, CURLOPT_URL, [fullFilePath
> cStringUsingEncoding:encoding]);
> curl_easy_setopt(curl, CURLOPT_USERNAME, [username
> cStringUsingEncoding:encoding]);
> curl_easy_setopt(curl, CURLOPT_PASSWORD, [password
> cStringUsingEncoding:encoding]);
> curl_easy_setopt(curl, CURLOPT_VERBOSE, (long)1);
> curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerList);
> CURLcode result = curl_easy_perform(curl);
> curl_slist_free_all (headerList);
> curl_easy_cleanup(curl);
>
>
> Thanks.
>
> Best Regards,
> Anders Havn
>
>
> On Thu, May 17, 2012 at 5:36 PM, Michael Wood <esiotrot_at_gmail.com> wrote:
>> Hi
>>
>> On 17 May 2012 15:24, Anders Havn <anders.havn_at_gmail.com> wrote:
>>> Hi,
>>>
>>> I have a problem when deleting/renaming/chmod a file if the file or
>>> the file path includes a space:
>>> Ex: "sftp://myftpserver.org/UserFolder/Test xyz.txt"  <-- space in filename
>>> Ex: "sftp://myftpserver.org/User Folder/Test.txt"       <-- space in filepath
>>>
>>> It works fine if the path have no spaces:
>>> Ex: "sftp://myftpserver.org/UserFolder/Test.txt"
>>>
>>> This is how my codes looks:
>>>
>>> NSString username = @"username";
>>> NSString password = @"password";
>>> NSString* fullFilePath = @"sftp://myftpserver.org/UserFolder/Test xyz.txt"
>>
>> That is not a valid URL.  You'll need to encode it.
>>
>> e.g.: @"sftp://example.org/UserFolder/Test%20xyz.txt"
>>
>>> NSString* filePath = @"rm /UserFolder/Test xyz.txt"
>>>  struct curl_slist* headerlist = curl_slist_append(NULL, [filePath
>>> cStringUsingEncoding:encoding]);
>>>
>>> curl_global_init(CURL_GLOBAL_DEFAULT);
>>> CURL *curl = curl_easy_init();
>>> curl_easy_setopt(curl, CURLOPT_URL, [fullFilePath
>>> cStringUsingEncoding:encoding]);
>>> curl_easy_setopt(curl, CURLOPT_USERNAME, [username
>>> cStringUsingEncoding:encoding]);
>>> curl_easy_setopt(curl, CURLOPT_PASSWORD, [password
>>> cStringUsingEncoding:encoding]);
>>> curl_easy_setopt(curl, CURLOPT_VERBOSE, (long)1);
>>> curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerList);
>>> CURLcode result = curl_easy_perform(curl);
>>> curl_slist_free_all (headerList);
>>> curl_easy_cleanup(curl);
>>>
>>>
>>> Just want to repeat again that the code works fine when there are no
>>> spaces involved in the filename or the full file path.
>>>
>>> Thank you for you help.
>>>
>>> Best Regards,
>>> Anders Havn
>>
>> --
>> Michael Wood <esiotrot_at_gmail.com>
>>
>> -------------------------------------------------------------------
>> List admin: http://cool.haxx.se/list/listinfo/curl-library
>> Etiquette:  http://curl.haxx.se/mail/etiquette.html

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-05-18