CURLOPT_NETRC.3 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_NETRC 3 "January 02, 2023" "libcurl 7.88.1" "curl_easy_setopt options"
  26. .SH NAME
  27. CURLOPT_NETRC \- enable use of .netrc
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_NETRC, long level);
  32. .fi
  33. .SH DESCRIPTION
  34. This parameter controls the preference \fIlevel\fP of libcurl between using
  35. user names and passwords from your \fI~/.netrc\fP file, relative to user names
  36. and passwords in the URL supplied with \fICURLOPT_URL(3)\fP.
  37. On Windows, libcurl will use the file as \fI%HOME%/_netrc\fP. If \fI%HOME%\fP
  38. is not set on Windows, libcurl falls back to \fI%USERPROFILE%\fP.
  39. You can also tell libcurl a different file name to use with
  40. \fICURLOPT_NETRC_FILE(3)\fP.
  41. libcurl uses a user name (and supplied or prompted password) supplied with
  42. \fICURLOPT_USERPWD(3)\fP or \fICURLOPT_USERNAME(3)\fP in preference to any of
  43. the options controlled by this parameter.
  44. Only machine name, user name and password are taken into account (init macros
  45. and similar things are not supported).
  46. libcurl does not verify that the file has the correct properties set (as the
  47. standard Unix ftp client does). It should only be readable by user.
  48. \fIlevel\fP is a long that should be set to one of the values described below.
  49. .IP "CURL_NETRC_IGNORED (0)"
  50. The library will ignore the \fI.netrc\fP file. This is the default.
  51. .IP "CURL_NETRC_OPTIONAL (1)"
  52. The use of the \fI.netrc\fP file is optional, and information in the URL is to
  53. be preferred. The file will be scanned for the host and user name (to find
  54. the password only) or for the host only, to find the first user name and
  55. password after that \fImachine\fP, which ever information is not specified.
  56. .IP "CURL_NETRC_REQUIRED (2)"
  57. The use of the \fI.netrc\fP file is required, and any credential information
  58. present in the URL is ignored. The file will be scanned for the host and user
  59. name (to find the password only) or for the host only, to find the first user
  60. name and password after that \fImachine\fP, which ever information is not
  61. specified.
  62. .SH FILE FORMAT
  63. The \fB.netrc\fP file format is simple: you specify lines with a machine name
  64. and follow the login and password that are associated with that machine.
  65. Each field is provided as a sequence of letters that ends with a space or
  66. newline. Starting in 7.84.0, libcurl also supports quoted strings. They start
  67. and end with double quotes and support the escaped special letters \\\", \\n,
  68. \\r, and \\t. Quoted strings are the only way a space character can be used in
  69. a user name or password.
  70. .IP "machine <name>"
  71. Provides credentials for a host called \fBname\fP. libcurl searches the .netrc
  72. file for a machine token that matches the host name specified in the URL. Once
  73. a match is made, the subsequent tokens are processed, stopping when the end of
  74. file is reached or another "machine" is encountered.
  75. .IP default
  76. This is the same as "machine" name except that default matches any name. There
  77. can be only one default token, and it must be after all machine tokens. To
  78. provide a default anonymous login for hosts that are not otherwise matched,
  79. add a line similar to this in the end:
  80. default login anonymous password user@domain
  81. .IP "login <name>"
  82. The user name string for the remote machine.
  83. .IP "password <secret>"
  84. Supply a password. If this token is present, curl will supply the specified
  85. string if the remote server requires a password as part of the login process.
  86. Note that if this token is present in the .netrc file you really should make
  87. sure the file is not readable by anyone besides the user.
  88. .IP "macdef <name>"
  89. Define a macro. This feature is not supported by libcurl. In order for the
  90. rest of the .netrc to still work fine, libcurl will properly skip every
  91. definition done with "macdef" that it finds.
  92. .SH DEFAULT
  93. CURL_NETRC_IGNORED
  94. .SH PROTOCOLS
  95. Most
  96. .SH EXAMPLE
  97. .nf
  98. CURL *curl = curl_easy_init();
  99. if(curl) {
  100. CURLcode ret;
  101. curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
  102. curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
  103. ret = curl_easy_perform(curl);
  104. }
  105. .fi
  106. .SH AVAILABILITY
  107. Always
  108. .SH RETURN VALUE
  109. Returns CURLE_OK
  110. .SH "SEE ALSO"
  111. .BR CURLOPT_USERPWD "(3), " CURLOPT_USERNAME "(3), " CURLOPT_NETRC_FILE "(3), "