GNURLOPT_NETRC(3)
π
GNURLOPT_NETRC(3) β like, the curl_easy_setopt options era, bestie π
okay so this page lives in the curl_easy_setopt options corner of the gnurl universe, and it's literally about letting libcurl read your ~/.netrc. yes. that file. the vibe check of "do I trust my saved passwords or not". let's go β¨
πΈ NAME πΈ
CURLOPT_NETRC β the "please go look at my .netrc" request, fr fr π
π¦ SYNOPSIS π¦
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_NETRC, long level);
β¨ DESCRIPTION β¨
So this parameter is the preference dial π β it controls the level of preference libcurl gives to user names and passwords from your ~/.netrc file, relative to the user names and passwords sitting right there in the URL you passed with CURLOPT_URL(3).
On Windows, libcurl will use the file as %HOME%/_netrc, but bestie you can also tell libcurl a different file name to use with CURLOPT_NETRC_FILE(3). convenient icon behavior π
Also super important: libcurl uses a user name (and supplied or prompted password) that you give it with CURLOPT_USERPWD(3) or CURLOPT_USERNAME(3) in preference to any of the options controlled by this parameter. like, your explicit creds win. main character energy π
Only machine name, user name and password are taken into account (init macros and similar things aren't supported). so don't come at it with the fancy stuff, it's not doing that π
And heads up β libcurl does not verify that the file has the correct properties set (as the standard Unix ftp client does). It should only be readable by user. like, actual security note, not just vibes: lock that file down. π
level should be set to one of the values described below. π
β the level values β
CURL_NETRC_OPTIONALβ using the~/.netrcfile is optional, and information in the URL is to be preferred. The file will be scanned for the host and user name (to find the password only) or for the host only, to find the first user name and password after that machine, which ever information is not specified. π«Ά Undefined values of the option will have this effect. so if you left it weird/unspecified, congrats, this is what you get π«CURL_NETRC_IGNOREDβ the library will ignore the~/.netrcfile. completely. not even a glance π This is the default. remember this one, it matters.CURL_NETRC_REQUIREDβ the use of the~/.netrcfile is required, and information in the URL is to be ignored. The file will be scanned for the host and user name (to find the password only) or for the host only, to find the first user name and password after that machine, which ever information is not specified. it's giving "netrc or nothing" π₯
π DEFAULT π
CURL_NETRC_IGNORED
yep, out of the box it just ignores the whole file. no cap.
π PROTOCOLS π
Most π (that's it, that's the whole section, slay)
π§ EXAMPLE π§
CURL *curl = curl_easy_init();
if(curl) {
CURLcode ret;
curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
ret = curl_easy_perform(curl);
}
see how it sets the URL first, then flips the netrc dial to CURL_NETRC_OPTIONAL, then performs? iconic sequence, don't rearrange it π
π AVAILABILITY π
Always β β literally always there for you, bestie.
π RETURN VALUE π
Returns CURLE_OK π
π«Ά SEE ALSO π«Ά
ok that's the whole page!! go forth and let your.netrclive its truth (or don't,CURL_NETRC_IGNOREDis the default after all π) π β¨
mwah π β written against libcurl 7.37.0, dated 17 Jun 2014, and this lil page is GNURLOPT_NETRC(3) in the manual, don't forget it π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms