2014-01-14 56 views
0

我使用libcurl示例http://curl.askapache.com/c/ftpupload.html在Linux上開發了'C'應用程序,我工作的很好。我被要求將SSL用於「控制通道和數據通道的數據加密」。我無法找到在我遵循的示例中添加SSL的示例。這裏是FTP程序的核心:使用Easy Curl在Linux上使用SSL進行FTP上傳

// get a FILE * of the same file 
hd_src = fopen(local_file, "rb"); 

// curl init 
curl_global_init(CURL_GLOBAL_ALL); 

// get a curl handle 
curl = curl_easy_init(); 

if (curl) { // build a list of commands to pass to libcurl 
    headerlist = curl_slist_append(headerlist, buf_1); 
#ifdef DEBUG 
    // we want to use our own read function 
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); 
#endif 

    // enable uploading 
    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); 

    // specify target 
    curl_easy_setopt(curl, CURLOPT_URL, ftp_url); 
    curl_easy_setopt(curl, CURLOPT_USERPWD, user_password); 
    curl_easy_setopt(curl, CURLOPT_PORT, 21); 

    // pass in that last of FTP commands to run after the transfer 
    curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist); 

    // now specify which file to upload 
    curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); 

    // Set the size of the file to upload 
    curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) fsize); 

    // Now run off and do what you've been told! 
    res = curl_easy_perform(curl); 

    // Check for errors 
    if (res != CURLE_OK) { 
     char *s; 
     s = malloc((sizeof(char) * 100) + 1); 
     sprintf(s, "curl_easy_perform() failed: %s - Error Number: %d\n", 
     curl_easy_strerror(res), res); 
     returnResults->error = true; 
     returnResults->errorMessage = s; 
     return returnResults; 
    } 

    // clean up the FTP commands list 
    curl_slist_free_all(headerlist); 

    // always cleanup 
    curl_easy_cleanup(curl); 
} 

fclose(hd_src); // close the local file 
curl_global_cleanup(); 
+0

你的問題是什麼? – imp25

回答

2

但是有一個在libcurl的網站現有的代碼示例展示瞭如何做FTP-SSL來下載文件:ftpsget.c - 它顯示了很少的SSL魔術你需要添加。這神奇的是上傳相同:

/* We activate SSL and we require it for both control and data */ 
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); 

事實上,你可以添加這一行到FTP upload example。它會爲你做FTPS上傳。

相關問題