CURLOPT_PUT.3 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. .\" generated by cd2nroff 0.1 from CURLOPT_PUT.md
  2. .TH CURLOPT_PUT 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_PUT \- make an HTTP PUT request
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PUT, long put);
  9. .fi
  10. .SH DESCRIPTION
  11. A parameter set to 1 tells the library to use HTTP PUT to transfer data. The
  12. data should be set with \fICURLOPT_READDATA(3)\fP and
  13. \fICURLOPT_INFILESIZE(3)\fP.
  14. This option is \fBdeprecated\fP since version 7.12.1. Use \fICURLOPT_UPLOAD(3)\fP.
  15. .SH DEFAULT
  16. 0, disabled
  17. .SH PROTOCOLS
  18. This functionality affects http only
  19. .SH EXAMPLE
  20. .nf
  21. static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
  22. {
  23. FILE *src = userdata;
  24. /* copy as much data as possible into the 'ptr' buffer, but no more than
  25. 'size' * 'nmemb' bytes */
  26. size_t retcode = fread(ptr, size, nmemb, src);
  27. return retcode;
  28. }
  29. int main(void)
  30. {
  31. CURL *curl = curl_easy_init();
  32. if(curl) {
  33. FILE *src = fopen("local-file", "r");
  34. curl_off_t fsize; /* set this to the size of the input file */
  35. /* we want to use our own read function */
  36. curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
  37. /* enable PUT */
  38. curl_easy_setopt(curl, CURLOPT_PUT, 1L);
  39. /* specify target */
  40. curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
  41. /* now specify which pointer to pass to our callback */
  42. curl_easy_setopt(curl, CURLOPT_READDATA, src);
  43. /* Set the size of the file to upload */
  44. curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
  45. /* Now run off and do what you have been told */
  46. curl_easy_perform(curl);
  47. }
  48. }
  49. .fi
  50. .SH DEPRECATED
  51. Deprecated since 7.12.1.
  52. .SH AVAILABILITY
  53. Added in curl 7.1
  54. .SH RETURN VALUE
  55. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
  56. .SH SEE ALSO
  57. .BR CURLOPT_HTTPGET (3),
  58. .BR CURLOPT_MIMEPOST (3),
  59. .BR CURLOPT_POSTFIELDS (3),
  60. .BR CURLOPT_UPLOAD (3)