2013-02-08 2 views
0

XCP에서 가상 호스트에 대해 일종의 마이그레이션을 수행하려고합니다.c libcurl 파이핑 HTTP GET 및 PUT

curl = curl_easy_init(); 
    //Auto escape user password 
    char *password = curl_easy_escape(curl, XEN.user_passwd, 0); 
    snprintf(api_req, sizeof(api_req), "http://%s:%[email protected]%s/import",XEN.user_name, password, XEN.host_ip); 
    curl_free(password); 
    puts(api_req); 
    TASK_LOG(api_req); 
    curl_upload=TRUE; 
    g_timeout_add_seconds(1, (GSourceFunc) update_progress_bar, 0); 
    abort_flag = 0; 
    curl_easy_setopt(curl, CURLOPT_URL, api_req); 
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, export_read_callback); 
    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); 
    curl_easy_setopt(curl, CURLOPT_PUT, 1L); 
    curl_easy_setopt(curl, CURLOPT_READDATA, xva); 
    curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,(curl_off_t)file_info.st_size); 
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE); 
    // Install the callback function 
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func); 
    puts("Upload started"); 
    TASK_LOG("Upload started"); 
    CURLcode res = curl_easy_perform(curl); 

I 필요한 경우 순간 내가 HTTP의 PUT와 다른 호스트에 업로드 한 후 HTTP GET을 사용하여 파일을 다운로드하고 그것을 할, 여기,

curl = curl_easy_init(); 
    //Auto escape user password 
    password = curl_easy_escape(curl, XEN.user_passwd, 0); 
    snprintf(api_req, sizeof(api_req), "http://%s:%[email protected]%s/export?uuid=%s", 
      XEN.user_name, password, XEN.host_ip, uuid); 
    curl_free(password); 
    puts(api_req); 
    TASK_LOG(api_req); 
    curl_download=TRUE; 
    curl_easy_setopt(curl, CURLOPT_URL, api_req); 
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write_func); 
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, xva_export); 
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE); 
    // Install the callback function 
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func); 
    //And....go! 
    run_progress_bar = TRUE; 
    //g_timeout_add_seconds(1, (GSourceFunc)update_progress_bar, 0); 
    res = curl_easy_perform(curl); 

업로드 다운로드의 예입니다 한 대의 컴퓨터에서 다른 컴퓨터로 트래픽을 직접 다운로드하지 않고 파이프로 전송할 수 있는지 궁금하십니까?

답변

1

로컬로 파일을 다운로드하려면 curl을 사용하고 있습니다.

scp을 사용하여 원본에서 대상으로 파일을 직접 복사하지 않는 이유는 무엇입니까?

+0

감사합니다. 사용하려고합니다. – pugnator

+0

모든 파일을 HTTP GET/PUT 요청을 통해서만 액세스 할 수 있다는 것을 잊어 버렸습니다. 이와 같이 http : // root : 1qa%40WS%[email protected]/export? uuid = 57cf4004-a776-4e10-5a26-fa9cb6d6bffc 그래서 scp는 도움이되지 않습니다 ... – pugnator

+0

왜 GET 요청을하지 마십시오 대상 컴퓨터에서? 내 요점은 중간 컴퓨터에 파일을 다운로드하고 대상 컴퓨터에 업로드하지 않아야한다는 것입니다. –