CURLOPT\_NETRC\_FILE(3) Library Functions Manual CURLOPT\_NETRC\_FILE(3)

# [NAME](#NAME)

CURLOPT\_NETRC\_FILE - filename to read .netrc info from

# [SYNOPSIS](#SYNOPSIS)

```
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_NETRC_FILE, char *file);
```

# [DESCRIPTION](#DESCRIPTION)

Pass a char pointer as parameter, pointing to a null-terminated string containing the full path name to the *file* you want libcurl to use as .netrc file. If this option is omitted, and [*CURLOPT\_NETRC(3)*](/man/os/curl/CURLOPT_NETRC.3) is set, libcurl checks for a .netrc file in the current user's home directory.

The application does not have to keep the string around after setting this option.

Using this option multiple times makes the last set string override the previous ones. Set it to NULL to disable its use again.

# [DEFAULT](#DEFAULT)

NULL

# [PROTOCOLS](#PROTOCOLS)

This functionality affects all supported protocols

# [EXAMPLE](#EXAMPLE)

```
int main(void)
{


  CURL *curl = curl_easy_init();


  if(curl) {


    CURLcode result;


    curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");


    curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);


    curl_easy_setopt(curl, CURLOPT_NETRC_FILE, "/tmp/magic-netrc");


    result = curl_easy_perform(curl);


  }
}
```

# [HISTORY](#HISTORY)

**CURL\_NETRC\_*** enums became *long* types in 8.13.0, prior to this version a *long* cast was necessary when passed to [*curl\_easy\_setopt(3)*](/man/os/curl/curl_easy_setopt.3).

# [AVAILABILITY](#AVAILABILITY)

Added in curl 7.11.0

# [RETURN VALUE](#RETURN_VALUE)

[*curl\_easy\_setopt(3)*](/man/os/curl/curl_easy_setopt.3) returns a CURLcode indicating success or error.

CURLE\_OK (0) means everything was OK, non-zero means an error occurred, see [*libcurl-errors(3)*](/man/os/curl/libcurl-errors.3).

# [SEE ALSO](#SEE_ALSO)

[**CURLOPT\_NETRC**(3)](/man/os/curl/CURLOPT_NETRC.3), [**CURLOPT\_PASSWORD**(3)](/man/os/curl/CURLOPT_PASSWORD.3), [**CURLOPT\_USERNAME**(3)](/man/os/curl/CURLOPT_USERNAME.3)

2026-10-01 libcurl

---

Document: CURLOPT_NETRC_FILE(3) from curl 8.22.0-r4 (Chainguard OS)
Source: https://github.com/curl/curl.git
