GNURLOPT_F...SSING_DIRS(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… NAME

CURLOPT_FTP_CREATE_MISSING_DIRS β€” bestie, this is the "just make the folder for me" option for FTP and SFTP. Yes, that's the whole vibe. ✨

(oh and ps β€” this whole page lives in the curl_easy_setopt options manual, page name GNURLOPT_F...SSING_DIRS(3), in case you were wondering where you wandered into 🫢)


🌸 SYNOPSIS

#include <gnurl/curl.h>

typedef enum {
  CURLFTP_CREATE_DIR_NONE,
  CURLFTP_CREATE_DIR,
  CURLFTP_CREATE_DIR_RETRY
} curl_ftpcreatedir;

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

πŸ¦‹ DESCRIPTION

Okay so you pass a long and that's you telling libcurl "go make the dir, king". If the value is CURLFTP_CREATE_DIR (1), libcurl will genuinely attempt to create any remote directory that it fails to "move" into. It's giving initiative. It's giving problem-solving. πŸ’…

For FTP requests, "fails to move into" means a CWD command fails. And CWD is literally the command that changes working directory β€” like the cd of the FTP world, no cap.

For SFTP requests, libcurl will attempt to create the remote directory if it can't obtain a handle to the target-location. And heads up, the creation will fail if a file of the same name as the directory to create already exists, or if a lack of permissions prevents creation. 😭 That's the vibe check failing, unfortunately.

Setting create to CURLFTP_CREATE_DIR_RETRY (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 the group project where everyone's lowkey doing the same task at the same time and somehow, bestie, it works out.


πŸŽ€ DEFAULT

CURLFTP_CREATE_DIR_NONE (0) β€” like, no dirs, no drama, nothing gets created unless you ask. πŸ™ˆ


🌈 PROTOCOLS

FTP and SFTP 🧚


πŸ’– EXAMPLE

CURL *curl = curl_easy_init();
if(curl) {
  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);

  ret = curl_easy_perform(curl);

  curl_easy_cleanup(curl);
}

Look at that URL β€” non-existing β€” and yet we're out here thriving and making directories anyway. Iconic behaviour, honestly. πŸ‘‘


⭐ AVAILABILITY

Added in 7.10.7. SFTP support added in 7.16.3. The retry option was added in 7.19.4. So if you're on something ancient, like, respectfully, this might not be your era. πŸ•°οΈ


πŸ“ RETURN VALUE

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if the create value is not. fr fr, that's the whole thing. ✨


πŸ‘‘ SEE ALSO


πŸ’€ Lowkey the biggest glow-up here is CURLFTP_CREATE_DIR_RETRY β€” simultaneous connections racing each other to MKD and everyone still winning? That's main character energy for a filesystem.

That's the whole page, bestie 🫢 β€” brought to you by libcurl 7.37.0, dated 19 Jun 2014, and signed off by GNURLOPT_F...SSING_DIRS(3). Go forth and make those dirs. πŸ’œ

πŸ“¦ where this page comes from