curl_easy_setopt(curl, CURLOPT_FTPPORT, str) 在远程计算机上 - 地址不可用

curl_easy_setopt(curl, CURLOPT_FTPPORT, str) on a remote computer - address is not available

我正在尝试将函数 'curl_easy_setopt' 与 'CURLOPT_FTPPORT' 选项一起使用,以将模式从被动模式更改为主动模式。

在本地计算机上,该功能按预期运行。

当我使用 curl_easy_setopt(curl, CURLOPT_FTPPORT, "-") 时在远程计算机上 - 有一个连接(我可以在 filezilla-server 日志中看到,文件也在传输)。

但是,当我使用curl_easy_setopt(curl, CURLOPT_FTPPORT, "TEST_STRING" )//TEST_STRING includes ip:port时,没有连接。在 filezilla-server 日志中出现以下信息:

bind (port=21) on non local address filed: address not available

Rejected command, Requested IP address does not match control connection IP

我的代码:

curl_easy_setopt(m_curl, CURLOPT_FTPPORT, "192.168.19.19:21");
rc = curl_easy_perform(m_curl);

rc returns CURL 错误 28 - 超时。

另外几个端口我都试过了,用netstat命令检查过

CURLOPT_FTPPORT 的值是错误的。

  • 首先不能是21端口,必须是本地空闲端口。在大多数系统上,它还必须高于 1024。

  • 并且IP地址必须是您的本地地址,而不是FTP服务器地址。它必须是 FTP 服务器从中接受您的连接的地址。


而且一般情况下,应该使用被动模式,而不是主动模式。有关详细信息,请参阅我在 FTP Connection Modes 上的文章。