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