xref: /curl/docs/libcurl/opts/CURLOPT_PUT.md (revision e3fe0200)
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
14---
15
16# NAME
17
18CURLOPT_PUT - make an HTTP PUT request
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PUT, long put);
26~~~
27
28# DESCRIPTION
29
30A parameter set to 1 tells the library to use HTTP PUT to transfer data. The
31data should be set with CURLOPT_READDATA(3) and
32CURLOPT_INFILESIZE(3).
33
34This option is **deprecated** since version 7.12.1. Use CURLOPT_UPLOAD(3).
35
36# DEFAULT
37
380, disabled
39
40# EXAMPLE
41
42~~~c
43static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
44{
45  FILE *src = userdata;
46  /* copy as much data as possible into the 'ptr' buffer, but no more than
47     'size' * 'nmemb' bytes */
48  size_t retcode = fread(ptr, size, nmemb, src);
49
50  return retcode;
51}
52
53int main(void)
54{
55  CURL *curl = curl_easy_init();
56  if(curl) {
57    FILE *src = fopen("local-file", "r");
58    curl_off_t fsize; /* set this to the size of the input file */
59
60    /* we want to use our own read function */
61    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
62
63    /* enable PUT */
64    curl_easy_setopt(curl, CURLOPT_PUT, 1L);
65
66    /* specify target */
67    curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
68
69    /* now specify which pointer to pass to our callback */
70    curl_easy_setopt(curl, CURLOPT_READDATA, src);
71
72    /* Set the size of the file to upload */
73    curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
74
75    /* Now run off and do what you have been told */
76    curl_easy_perform(curl);
77  }
78}
79~~~
80
81# AVAILABILITY
82
83Deprecated since 7.12.1. Do not use.
84
85# RETURN VALUE
86
87Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
88