1CURLOPT_NETRC(3) curl_easy_setopt options CURLOPT_NETRC(3)
2
3
4
6 CURLOPT_NETRC - enable use of .netrc
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_NETRC, long level);
12
14 This parameter controls the preference level of libcurl between using
15 user names and passwords from your ~/.netrc file, relative to user
16 names and passwords in the URL supplied with CURLOPT_URL(3). On Win‐
17 dows, libcurl will use the file as %HOME%/_netrc, but you can also tell
18 libcurl a different file name to use with CURLOPT_NETRC_FILE(3).
19
20 libcurl uses a user name (and supplied or prompted password) supplied
21 with CURLOPT_USERPWD(3) or CURLOPT_USERNAME(3) in preference to any of
22 the options controlled by this parameter.
23
24 Only machine name, user name and password are taken into account (init
25 macros and similar things are not supported).
26
27 libcurl does not verify that the file has the correct properties set
28 (as the standard Unix ftp client does). It should only be readable by
29 user.
30
31 level is a long that should be set to one of the values described be‐
32 low.
33
34 CURL_NETRC_IGNORED (0)
35 The library will ignore the .netrc file. This is the default.
36
37 CURL_NETRC_OPTIONAL (1)
38 The use of the .netrc file is optional, and information in the
39 URL is to be preferred. The file will be scanned for the host
40 and user name (to find the password only) or for the host only,
41 to find the first user name and password after that machine,
42 which ever information is not specified.
43
44 CURL_NETRC_REQUIRED (2)
45 The use of the .netrc file is required, and any credential in‐
46 formation present in the URL is ignored. The file will be
47 scanned for the host and user name (to find the password only)
48 or for the host only, to find the first user name and password
49 after that machine, which ever information is not specified.
50
52 CURL_NETRC_IGNORED
53
55 Most
56
58 CURL *curl = curl_easy_init();
59 if(curl) {
60 CURLcode ret;
61 curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
62 curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
63 ret = curl_easy_perform(curl);
64 }
65
67 Always
68
70 Returns CURLE_OK
71
73 CURLOPT_USERPWD(3), CURLOPT_USERNAME(3), CURLOPT_NETRC_FILE(3),
74
75
76
77libcurl 7.82.0 January 07, 2022 CURLOPT_NETRC(3)