【发布时间】:2015-12-14 12:12:37
【问题描述】:
我正在使用 C 程序连接到 ftp 服务器并上传文件。以前服务器没有使用 SSL,我可以使用以下代码上传文件:
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, throw_away);
curl_easy_setopt(curl, CURLOPT_USERNAME, "username");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "password");
if (CURLE_OK != (res = curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftpb.****.com")))
{
printf("Failed to check ftp url, Error : %s : %d\n", curl_easy_strerror(res), res);
}
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
// Connection establishment timeout
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 20);
printf("Trying to connect...\n");
if (CURLE_OK != (res = curl_easy_perform(curl)))
{
/* If fail to connect */
printf("FTP connection failed...%s : %d\n", strerror(res), res);
}
else
{
/* If connected succesfully */
printf("Connected to FTP successfully...\n");
/****** proceed with upload ******/
}
}
ftp服务器切换为使用SSL认证后,我在代码中添加了以下行以使用SSL:
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
现在,当我运行程序时,我的应用程序无法连接到 FTP 并显示消息:
"FTP 连接失败...参数列表太长:7"
即使我不添加CURLOPT_USE_SSL 部分也会得到相同的错误。
我可以使用 Filezilla 连接到 ftp 服务器(仅当我将 ftps 添加到地址时)。在我的代码中添加 ftps 会出现错误:
“FTP 连接失败...设备不是流:60”
有人知道解决方法吗?
【问题讨论】: