gpt4 book ai didi

c libcurl 管道 HTTP GET 和 PUT

转载 作者:行者123 更新时间:2023-11-30 15:51:57 26 4
gpt4 key购买 nike

我想对 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com