CURLOPT_NETRC.3 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. .\" generated by cd2nroff 0.1 from CURLOPT_NETRC.md
  2. .TH CURLOPT_NETRC 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_NETRC \- enable use of .netrc
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_NETRC, long level);
  9. .fi
  10. .SH DESCRIPTION
  11. This parameter controls the preference \fIlevel\fP of libcurl between using
  12. usernames and passwords from your \fI~/.netrc\fP file, relative to usernames and
  13. passwords in the URL supplied with \fICURLOPT_URL(3)\fP.
  14. On Windows, libcurl primarily checks for \fI.netrc\fP in \fI%HOME%\fP. If \fI%HOME%\fP is
  15. not set on Windows, libcurl falls back to \fI%USERPROFILE%\fP. If the file does
  16. not exist, it falls back to check if there is instead a file named \fI_netrc\fP \-
  17. using an underscore instead of period.
  18. You can also tell libcurl a different filename to use with
  19. \fICURLOPT_NETRC_FILE(3)\fP.
  20. libcurl uses a username (and supplied or prompted password) supplied with
  21. \fICURLOPT_USERPWD(3)\fP or \fICURLOPT_USERNAME(3)\fP in preference to any of
  22. the options controlled by this parameter.
  23. Only machine name, username and password are taken into account (init macros
  24. and similar things are not supported).
  25. libcurl does not verify that the file has the correct properties set (as the
  26. standard Unix ftp client does). It should only be readable by user.
  27. \fIlevel\fP is a long that should be set to one of the values described below.
  28. .IP "CURL_NETRC_IGNORED (0)"
  29. libcurl ignores the \fI.netrc\fP file. This is the default.
  30. .IP "CURL_NETRC_OPTIONAL (1)"
  31. The use of the \fI.netrc\fP file is optional, and information in the URL is to
  32. be preferred. The file is scanned for the host and username (to find the
  33. password only) or for the host only, to find the first username and password
  34. after that \fImachine\fP, which ever information is not specified.
  35. .IP "CURL_NETRC_REQUIRED (2)"
  36. The use of the \fI.netrc\fP file is required, and any credential information
  37. present in the URL is ignored. The file is scanned for the host and username
  38. (to find the password only) or for the host only, to find the first username
  39. and password after that \fImachine\fP, which ever information is not
  40. specified.
  41. .SH FILE FORMAT
  42. The \fB.netrc\fP file format is simple: you specify lines with a machine name
  43. and follow the login and password that are associated with that machine.
  44. Each field is provided as a sequence of letters that ends with a space or
  45. newline. Starting in 7.84.0, libcurl also supports quoted strings. They start
  46. and end with double quotes and support the escaped special letters ", n,
  47. r, and t. Quoted strings are the only way a space character can be used in
  48. a username or password.
  49. .IP "machine \<name\>"
  50. Provides credentials for a host called \fBname\fP. libcurl searches the .netrc
  51. file for a machine token that matches the hostname specified in the URL. Once
  52. a match is made, the subsequent tokens are processed, stopping when the end of
  53. file is reached or another "machine" is encountered.
  54. .IP default
  55. This is the same as machine name except that default matches any name. There
  56. can be only one default token, and it must be after all machine tokens. To
  57. provide a default anonymous login for hosts that are not otherwise matched,
  58. add a line similar to this in the end:
  59. .nf
  60. default login anonymous password user@domain
  61. .fi
  62. .IP "login \<name\>"
  63. The username string for the remote machine.
  64. .IP "password \<secret\>"
  65. Supply a password. If this token is present, curl supplies the specified
  66. string if the remote server requires a password as part of the login process.
  67. Note that if this token is present in the .netrc file you really should make
  68. sure the file is not readable by anyone besides the user.
  69. .IP "macdef \<name\>"
  70. Define a macro. This feature is not supported by libcurl. In order for the
  71. rest of the .netrc to still work fine, libcurl properly skips every definition
  72. done with "macdef" that it finds.
  73. .SH DEFAULT
  74. CURL_NETRC_IGNORED
  75. .SH PROTOCOLS
  76. This functionality affects all supported protocols
  77. .SH EXAMPLE
  78. .nf
  79. int main(void)
  80. {
  81. CURL *curl = curl_easy_init();
  82. if(curl) {
  83. CURLcode ret;
  84. curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
  85. curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
  86. ret = curl_easy_perform(curl);
  87. }
  88. }
  89. .fi
  90. .SH AVAILABILITY
  91. Added in curl 7.1
  92. .SH RETURN VALUE
  93. Returns CURLE_OK
  94. .SH SEE ALSO
  95. .BR CURLOPT_NETRC_FILE (3),
  96. .BR CURLOPT_USERNAME (3),
  97. .BR CURLOPT_USERPWD (3)