1--- 2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_FTP_CREATE_MISSING_DIRS 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_FTP_FILEMETHOD (3) 9 - CURLOPT_FTP_USE_EPSV (3) 10--- 11 12# NAME 13 14CURLOPT_FTP_CREATE_MISSING_DIRS - create missing directories for FTP and SFTP 15 16# SYNOPSIS 17 18~~~c 19#include <curl/curl.h> 20 21typedef enum { 22 CURLFTP_CREATE_DIR_NONE, 23 CURLFTP_CREATE_DIR, 24 CURLFTP_CREATE_DIR_RETRY 25} curl_ftpcreatedir; 26 27CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 28 long create); 29~~~ 30 31# DESCRIPTION 32 33Pass a long telling libcurl to *create* the dir. If the value is 34*CURLFTP_CREATE_DIR* (1), libcurl may create any remote directory that it 35fails to "move" into. 36 37For FTP requests, that means a CWD command fails. CWD being the command that 38changes working directory. 39 40For SFTP requests, libcurl may create the remote directory if it cannot obtain 41a handle to the target-location. The creation fails if a file of the same name 42as the directory to create already exists or lack of permissions prevents 43creation. 44 45Setting *create* to *CURLFTP_CREATE_DIR_RETRY* (2), tells libcurl to 46retry the CWD command again if the subsequent **MKD** command fails. This is 47especially useful if you are doing many simultaneous connections against the 48same server and they all have this option enabled, as then CWD may first fail 49but then another connection does **MKD** before this connection and thus 50**MKD** fails but trying CWD works! 51 52# DEFAULT 53 54CURLFTP_CREATE_DIR_NONE (0) 55 56# PROTOCOLS 57 58FTP and SFTP 59 60# EXAMPLE 61 62~~~c 63int main(void) 64{ 65 CURL *curl = curl_easy_init(); 66 if(curl) { 67 CURLcode res; 68 curl_easy_setopt(curl, CURLOPT_URL, 69 "ftp://example.com/non-existing/new.txt"); 70 curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 71 (long)CURLFTP_CREATE_DIR_RETRY); 72 73 res = curl_easy_perform(curl); 74 75 curl_easy_cleanup(curl); 76 } 77} 78~~~ 79 80# AVAILABILITY 81 82Added in 7.10.7. SFTP support added in 7.16.3. The retry option was added in 837.19.4. 84 85# RETURN VALUE 86 87Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if the 88create value is not. 89