2014-01-14 5 views
0

libcurl 예제를 사용하여 Linux 상자에서 'C'응용 프로그램을 개발했습니다. http://curl.askapache.com/c/ftpupload.html 정상적으로 작동합니다. 나는 "제어 채널과 데이터 채널 모두에 대한 데이터 암호화"에 SSL을 사용하도록 요청 받았다. 내가 뒤 따르는 예제에 SSL을 추가하는 예를 찾을 수 없었다. 그것은 아주 작은 SSL 마술을 보여줍니다 - ftpsget.c :Easy Curl을 사용하여 Linux에서 FTP를 사용하여 업로드

당신이 다운로드에 파일을 FTP-SSL을 어떻게 보여주는 libcurl에 사이트에 기존의 예제 코드 그러나있다
// 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

이 다음은 FTP 프로그램의 핵심이다 추가해야합니다. 그 마법은 업로드 동일합니다

/* 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 업로드를 할 것입니다.

관련 문제