pugnator
pugnator

Reputation: 725

c libcurl piping HTTP GET and PUT

I want to make some kind of migrations for virtual hosts in XCP. At the moment I do it by downloading the file with HTTP GET and then uploading it to another host with HTTP PUT, here is example of downloading

    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:%s@%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);

And uploading, if needed

    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:%s@%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 just wonder if it possible to pipe traffic directly from one machine to another without downloading it?

Upvotes: 0

Views: 591

Answers (1)

Forhad Ahmed
Forhad Ahmed

Reputation: 1771

You are using curl to download the file locally and then upload it.

Why not directly copy the file from source to destination using scp?

Upvotes: 1

Related Questions