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
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms