CURLOPT_PUT(3)

πŸ’… CURLOPT_PUT β€” make an HTTP PUT request πŸ’…

okay so bestie, this is CURLOPT_PUT(3) from the libcurl manual, and I'm gonna walk you through it like we're texting at 2am 🫢


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PUT, long put);

🌸 DESCRIPTION 🌸

So like, you set this parameter to 1 and it tells the library "hey babe, use HTTP PUT to transfer data" ✨ The data itself should be set with CURLOPT_READDATA(3) and CURLOPT_INFILESIZE(3) β€” those two are your besties here, don't forget them πŸ’–

ngl this option is deprecated since version 7.12.1 😭 Use CURLOPT_UPLOAD(3) instead. periodt.

πŸŽ€ DEFAULT πŸŽ€

0, disabled β€” like, it's off unless you say otherwise, lowkey shy of it πŸ’…

πŸ¦‹ PROTOCOLS πŸ¦‹

This functionality affects http only. that's it. that's the whole vibe πŸ“

πŸ’œ EXAMPLE πŸ’œ

here's the whole thing, copied exactly, no cap:

static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
{
  FILE *src = userdata;
  /* copy as much data as possible into the 'ptr' buffer, but no more than
     'size' * 'nmemb' bytes */
  size_t retcode = fread(ptr, size, nmemb, src);

  return retcode;
}

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    FILE *src = fopen("local-file", "r");
    curl_off_t fsize = 123456; /* set this to the size of the input file */

    /* we want to use our own read function */
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);

    /* enable PUT */
    curl_easy_setopt(curl, CURLOPT_PUT, 1L);

    /* specify target */
    curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");

    /* now specify which pointer to pass to our callback */
    curl_easy_setopt(curl, CURLOPT_READDATA, src);

    /* Set the size of the file to upload */
    curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);

    /* Now run off and do what you have been told */
    curl_easy_perform(curl);
  }
}

πŸ™ˆ DEPRECATED πŸ™ˆ

Deprecated since 7.12.1. yeah. it's giving "still works but please move on" energy πŸ’€

⭐ AVAILABILITY ⭐

Added in curl 7.1 β€” vintage, iconic, kind of an elder 🧚

🌈 RETURN VALUE 🌈

curl_easy_setopt(3) returns a CURLcode indicating success or error, iykyk πŸ‘‘

  • CURLE_OK (0) means everything was OK ✨
  • non-zero means an error occurred 😭 β€” see libcurl-errors(3) for the lore

πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page bestie!! 🫢 mwah πŸ’–

okay so the sign-off: this lil masterpiece is from libcurl, dated 2026-10-12, and it's literally CURLOPT_PUT(3) β€” write it down so you don't forget, ily, bye πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from