I am using a C program to connect to an ftp server and upload a file. Previously the server was not using SSL and I was able to do the file upload using the following code :
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 ******/
}
}
After the ftp server switched to use SSL certification, I added the following line to my code to use SSL:
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
Now, when I run the program, my application fails to connect to FTP and show the message :
"FTP connection failed...Argument list too long : 7"
The same error is obtained even if I do not add the CURLOPT_USE_SSL
part.
I am able to connect to the ftp server using Filezilla (only if I add ftps to the address). Adding ftps in my code gives the error:
"FTP connection failed...Device not a stream : 60"
Anybody knows a workaround for this?
You cannot use strerror()
on a return code from libcurl. libcurl provides its own strerror()
version for its return codes. See curl_easy_strerror .
You can also see the errors on the libcurl-errors man page, and there you learn that 7 means CURLE_COULDNT_CONNECT: "Failed to connect() to host or proxy"
. This is probably because you don't run the ftp server on port 21 which is the default port for FTP.
The error 60 you then mention is CURLE_SSL_CACERT
which indicates you got further but libcurl failed to verify your server.
I was able to fix the issue by adding the line
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
The application does not try to validate the SSL certificates now and proceeds with the connection
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.