c libcurl 管道 HTTP GET 和 PUT

标签 c libcurl

我想对 XCP 中的虚拟主机进行某种迁移。 目前,我通过使用 HTTP GET 下载文件,然后使用 HTTP PUT 将其上传到另一台主机来实现,这是下载示例

    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);

如果需要的话还可以上传

    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);

我只是想知道是否可以将流量直接从一台计算机传输到另一台计算机而无需下载?

最佳答案

您正在使用curl将文件下载到本地然后上传。

为什么不使用 scp 直接将文件从源复制到目标?

关于c libcurl 管道 HTTP GET 和 PUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14772143/

相关文章:

c - Linux、C、ncurses : seg fault caused by printw

c - 如何读取C中输入的2行整数?

libcurl - 使用curl_easy_pause时缓冲区保存在哪里

c++ - 过程控制

c - 为什么编译器会被 unsigned int 混淆成一个 SIGSEGV?

c - 将decimal/int转换为float时如何决定何时舍入

c++ - 可执行错误 : Can't start program

c - 用于文件下载的 libcurl 控制台进度条

ubuntu - 在 ubuntu 15.10 上快速构建错误

c++ - 如何解决 Borland C++(5.02 版)中的 libCurl 链接器错误?