CURLOPT_FTPPORT(3)

πŸ’… CURLOPT_FTPPORT β€” the "make FTP transfer active" page, bestie

okay so this is a libcurl manpage, CURLOPT_FTPPORT(3), and it's literally about flipping your FTP transfer into active mode. sit down, grab a strawberry drink πŸ“, and let's get into it.


✨ NAME ✨

CURLOPT_FTPPORT β€” make FTP transfer active 🫢


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FTPPORT, char *spec);

πŸ¦‹ DESCRIPTION πŸ¦‹

So you pass a pointer to a null-terminated string as the parameter. That string is like, the whole vibe of the operation: it says "yes, make this FTP transfer active", and then the string itself is what's used to get the IP address for the FTP PORT instruction. πŸ’…

The PORT instruction basically tells the remote server "hi bestie, do a TCP connect to this IP address we're specifying." And the string you give can be a bunch of things:

  • a plain IP address
  • a hostname
  • a network interface name (under Unix)
  • or just a - symbol, which lets the library use your system's default IP address

Default FTP operations are passive, and does not use the PORT command. periodt.

The address can be followed by a : to specify a port, optionally followed by a - to specify a port range. If the port specified is 0, the operating system picks a free port. If a range is provided and all the ports in that range are not available, libcurl reports CURLE_FTP_PORT_FAILED for the handle. 😭 Invalid port/range settings are ignored, ngl.

IPv6 addresses followed by a port or port range have to be in brackets. IPv6 addresses without a port/range specifier can be in brackets.

Examples with specified ports β€” iconic:

eth0:0
192.168.1.2:32000-33000
curl.se:32123
[::1]:1234-4567
🚨 We strongly advise against specifying the address with a name, because it causes libcurl to do a blocking name resolve call to retrieve the IP address. And that name resolve operation does not use DNS-over-HTTPS even if CURLOPT_DOH_URL(3) is set. so like… don't do it unless you know what you're doing βœ‹

Using anything else than - for this option should typically only be done if you have special knowledge and confirmation that it works. iykyk.

Good news though: 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. And if you want to disable PORT again and go back to using the passive version, just set this option to NULL. slay.


πŸŽ€ DEFAULT πŸŽ€

NULL


🌈 PROTOCOLS 🌈

This functionality affects ftp only πŸ’€ (yeah, just the one)


⭐ EXAMPLE ⭐

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL,
                     "ftp://example.com/old-server/file.txt");
    curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

πŸ’œ AVAILABILITY πŸ’œ

Added in curl 7.1 β€” she's been around a minute πŸ‘‘


πŸ”₯ RETURN VALUE πŸ”₯

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK β€” main character energy ✨. Non-zero means an error occurred, see libcurl-errors(3).


🧚 SEE ALSO 🧚


and that's the page, bestie 🫢 this was libcurl, dated 2026-10-12 β€” go forth and configure responsibly πŸ’–πŸŒΈ

πŸ“¦ where this page comes from