CURLOPT_FTP_CREATE_MISSING_DIRS(3)

πŸ’… CURLOPT_FTP_CREATE_MISSING_DIRS πŸ’…

okay so bestie, welcome to the CURLOPT_FTP_CREATE_MISSING_DIRS(3) page β€” yes that's the full name, it's from the Library Functions Manual and it's giving "long title, big brain" energy. let's get into it ✨


🌸 NAME 🌸

CURLOPT_FTP_CREATE_MISSING_DIRS β€” literally "create missing directories for FTP and SFTP". that's it, that's the whole vibe. πŸŽ€


✨ SYNOPSIS ✨

#include <curl/curl.h>

#define CURLFTP_CREATE_DIR_NONE  0L
#define CURLFTP_CREATE_DIR       1L
#define CURLFTP_CREATE_DIR_RETRY 2L

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FTP_CREATE_MISSING_DIRS,
                          long create);

three defines, one curl_easy_setopt call, zero notes. slay. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so you pass a long and it tells libcurl to create the dir. that's the whole assignment.

if the value is CURLFTP_CREATE_DIR (that's 1), libcurl may create any remote directory that it fails to "move" into. like, it tried to get in and the door was locked, so it just builds a door. iconic. πŸ’…

for FTP requests, that means a CWD command fails. (CWD being the command that changes working directory, iykyk.)

for SFTP requests, libcurl may create the remote directory if it can't obtain a handle to the target-location. now listen β€” the creation fails if a file with the same name as the directory-to-create already exists, or if lack of permissions prevents creation. so like, no cap, sometimes it just doesn't work and that's a permissions thing, not a you thing. 😭

setting create to CURLFTP_CREATE_DIR_RETRY (that's 2) tells libcurl to retry the CWD command again if the subsequent MKD command fails. this is especially useful if you're doing many simultaneous connections against the same server and they all have this option enabled β€” because then CWD may first fail, but then another connection does MKD before this connection, and thus MKD fails but trying CWD works. it's a whole group-chat race condition and this option is the friend who double-texts. πŸ”₯


⭐ DEFAULT ⭐

CURLFTP_CREATE_DIR_NONE (0)

like, by default we are NOT creating dirs. we're respecting boundaries. πŸ™ˆ


🌈 PROTOCOLS 🌈

this functionality affects ftp only. that's the tea. πŸ“


πŸ‘‘ EXAMPLE πŸ‘‘

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL,
                     "ftp://example.com/non-existing/new.txt");
    curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS,
                     CURLFTP_CREATE_DIR_RETRY);

    result = curl_easy_perform(curl);

    curl_easy_cleanup(curl);
  }
}

look at her go. init, setopt, setopt, perform, cleanup. the full main character arc. πŸ’–

heads up bestie: in the example, result gets assigned from curl_easy_perform(curl) β€” that's exactly how it's written in the source, so keep it that way. πŸŽ€

🧚 HISTORY 🧚

the CURLFTP_CREATE_* enums became long types in 8.16.0. prior to this version, a long cast was necessary when passed to curl_easy_setopt(3). so if you're on old curl, cast it. if you're on new curl, live your truth. ✨


πŸ’œ AVAILABILITY πŸ’œ

added in curl 7.10.7. ancient. vintage. a classic. πŸ•°οΈ


🩷 RETURN VALUE 🩷

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK β€” we love a zero. non-zero means an error occurred, so go see libcurl-errors(3). πŸ’€


πŸŽ€ SEE ALSO πŸŽ€


okay that's the whole page, bestie!! go forth and create those missing dirs πŸ¦‹πŸ’…

libcurl Β· 2026-10-12 Β· and the header/footer were screaming CURLOPT_FT...ISSING_DIRS(3) the whole time because apparently even man pages get truncation anxiety πŸ˜­πŸ’– mwah, bye!! 🫢✨

πŸ“¦ where this page comes from