xref: /curl/docs/libcurl/opts/CURLOPT_FTPPORT.md (revision e3fe0200)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_FTPPORT
5Section: 3
6Source: libcurl
7Protocol:
8  - FTP
9See-also:
10  - CURLOPT_FTP_USE_EPRT (3)
11  - CURLOPT_FTP_USE_EPSV (3)
12---
13
14# NAME
15
16CURLOPT_FTPPORT - make FTP transfer active
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FTPPORT, char *spec);
24~~~
25
26# DESCRIPTION
27
28Pass a pointer to a null-terminated string as parameter. It specifies that the
29FTP transfer should be made actively and the given string is used to get the
30IP address to use for the FTP PORT instruction.
31
32The PORT instruction tells the remote server to do a TCP connect to our
33specified IP address. The string may be a plain IP address, a hostname, a
34network interface name (under Unix) or just a '-' symbol to let the library
35use your system's default IP address. Default FTP operations are passive, and
36does not use the PORT command.
37
38The address can be followed by a ':' to specify a port, optionally followed by
39a '-' to specify a port range. If the port specified is 0, the operating
40system picks a free port. If a range is provided and all ports in the range
41are not available, libcurl reports CURLE_FTP_PORT_FAILED for the
42handle. Invalid port/range settings are ignored. IPv6 addresses followed by a
43port or port range have to be in brackets. IPv6 addresses without port/range
44specifier can be in brackets.
45
46Examples with specified ports:
47
48~~~c
49  eth0:0
50  192.168.1.2:32000-33000
51  curl.se:32123
52  [::1]:1234-4567
53~~~
54
55We strongly advise against specifying the address with a name, as it causes
56libcurl to do a blocking name resolve call to retrieve the IP address. That
57name resolve operation does **not** use DNS-over-HTTPS even if
58CURLOPT_DOH_URL(3) is set.
59
60Using anything else than "-" for this option should typically only be done if
61you have special knowledge and confirmation that it works.
62
63You disable PORT again and go back to using the passive version by setting
64this option to NULL.
65
66The application does not have to keep the string around after setting this
67option.
68
69# DEFAULT
70
71NULL
72
73# EXAMPLE
74
75~~~c
76int main(void)
77{
78  CURL *curl = curl_easy_init();
79  if(curl) {
80    CURLcode res;
81    curl_easy_setopt(curl, CURLOPT_URL,
82                     "ftp://example.com/old-server/file.txt");
83    curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
84    res = curl_easy_perform(curl);
85    curl_easy_cleanup(curl);
86  }
87}
88~~~
89
90# AVAILABILITY
91
92Port range support was added in 7.19.5
93
94# RETURN VALUE
95
96Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
97CURLE_OUT_OF_MEMORY if there was insufficient heap space.
98