1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_PUT 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_HTTPGET (3) 9 - CURLOPT_MIMEPOST (3) 10 - CURLOPT_POSTFIELDS (3) 11 - CURLOPT_UPLOAD (3) 12Protocol: 13 - HTTP 14Added-in: 7.1 15--- 16 17# NAME 18 19CURLOPT_PUT - make an HTTP PUT request 20 21# SYNOPSIS 22 23~~~c 24#include <curl/curl.h> 25 26CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PUT, long put); 27~~~ 28 29# DESCRIPTION 30 31A parameter set to 1 tells the library to use HTTP PUT to transfer data. The 32data should be set with CURLOPT_READDATA(3) and 33CURLOPT_INFILESIZE(3). 34 35This option is **deprecated** since version 7.12.1. Use CURLOPT_UPLOAD(3). 36 37# DEFAULT 38 390, disabled 40 41# %PROTOCOLS% 42 43# EXAMPLE 44 45~~~c 46static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userdata) 47{ 48 FILE *src = userdata; 49 /* copy as much data as possible into the 'ptr' buffer, but no more than 50 'size' * 'nmemb' bytes */ 51 size_t retcode = fread(ptr, size, nmemb, src); 52 53 return retcode; 54} 55 56int main(void) 57{ 58 CURL *curl = curl_easy_init(); 59 if(curl) { 60 FILE *src = fopen("local-file", "r"); 61 curl_off_t fsize; /* set this to the size of the input file */ 62 63 /* we want to use our own read function */ 64 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb); 65 66 /* enable PUT */ 67 curl_easy_setopt(curl, CURLOPT_PUT, 1L); 68 69 /* specify target */ 70 curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile"); 71 72 /* now specify which pointer to pass to our callback */ 73 curl_easy_setopt(curl, CURLOPT_READDATA, src); 74 75 /* Set the size of the file to upload */ 76 curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize); 77 78 /* Now run off and do what you have been told */ 79 curl_easy_perform(curl); 80 } 81} 82~~~ 83 84# DEPRECATED 85 86Deprecated since 7.12.1. 87 88# %AVAILABILITY% 89 90# RETURN VALUE 91 92Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not. 93