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