I am trying to access a FTP using credentials.
I have never used curl and have limited understanding of what I'm doing, although I did research a lot of the functions I used. I have once developped a working FTP client and server in C, but it was unix only and a while ago, so it's mostly a curl problem to me (I really want to use curl as this has to be cross platform and I don't feel like wrapping everything myself besides I'm certain I'll have to know how to use curl eventually.)
The code so far (header file not included but I really doubt it's needed, password and login hidden for obvious reasons. They work, tested in filezilla)
bool FTPClient::DownloadFile()
{
CURL *curl;
CURLcode res;
char buffer[CURL_ERROR_SIZE + 1] = {};
struct FtpFile ftpfile =
{
"test",
NULL
};
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL,
"https://[login]:[password]@lifesanctuary.eu/Update");
curl_easy_setopt(curl, CURLOPT_PORT, 21);
curl_easy_setopt(curl, CURLOPT_SSL_CIPHER_LIST, "TLSv1");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, buffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (CURLE_OK != res)
{
//ERREUR
fprintf(stderr, "erreur CURL %d:\n%s\n", res, buffer);
curl_global_cleanup();
return false;
}
}
if (ftpfile.stream)
fclose(ftpfile.stream);
curl_global_cleanup();
return true;
}
Output:
* Trying 91.121.145.87...
* TCP_NODELAY set
* Connected to lifesanctuary.eu (91.121.145.87) port 21 (#0)
* schannel: SSL/TLS connection with lifesanctuary.eu port 21 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 185 bytes...
* schannel: sent initial handshake data: sent 185 bytes
* schannel: SSL/TLS connection with lifesanctuary.eu port 21 (step 2/3)
* schannel: failed to receive handshake, need more data
* schannel: SSL/TLS connection with lifesanctuary.eu port 21 (step 2/3)
* schannel: encrypted data got 53
* schannel: encrypted data buffer: offset 53 length 4096
* schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - Le jeton fourni Ó la fonction nÆest pas valide
* Closing connection 0
* schannel: shutting down SSL/TLS connection with lifesanctuary.eu port 21
* schannel: clear security context handle
erreur CURL 35:
schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - Le jeton fourni Ó la fonction nÆest pas valide
I don't know what the problem is. I have leads, searched up a bit and came to the conclusion that I either found things that were unrelated, or that I simply didn't understand.
For one it might be because of the encryption, SSL/TLS - I'm not very knowledgeable in that domain, the person who set up the server told me it used TLS, hence why I put that line:
curl_easy_setopt(curl, CURLOPT_SSL_CIPHER_LIST, "TLSv1");
But I got no real idea how else to do it and it seems "TLSv1" was the only parameter I thought could fit in my context. I suspect it might be the problem.
Also, another problem I believe could be certificate related. I'm not entirely sure why but I'm sure that I didn't handle anything certificate related, and I'm not exactly sure what they are either. I know that I get to accept it when I log into my ftp with filezilla, but here I obviously don't.
So what is going on? Certificate problem? Encryption problem? Maybe something completely different? Thanks in advance.
EDIT: - I am assuming it is a certificate problem because to my knowledge anything https needs one and I don't handle anything on that regard, - I am considering it may be an encryption problem because this error code mostly seems to be caused by that - I don't know for sure at all it might very well be something else!
I think a series of misinformations from the person handing this server are in cause. I was told multiple times to use "https://" while it seems obvious that "ftp://" should be used and now I get a different error that seems to indicate I should not be using the encryption system he said I should use. I am closing this question as it sounds more of a problem from the team rather than from the code.
User contributions licensed under CC BY-SA 3.0