gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
使用libcurl实现FtpClient 支持文件批量下载
- User
使用libcurl实现FtpClient 支持文件批量下载
- Assistant
以下是使用libcurl实现FtpClient支持文件批量下载的示例代码:
code
使用libcurl实现FtpClient 支持文件批量下载
以下是使用libcurl实现FtpClient支持文件批量下载的示例代码:
#include <stdio.h>
#include <curl/curl.h>
int main(int argc, char *argv[]) {
CURL *curl;
CURLcode res;
FILE *fp;
char *url;
char filename[256];
if (argc < 3) {
printf("Usage: %s <server_url> <file_list>\n", argv[0]);
return 1;
}
url = argv[1];
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (!curl) {
printf("curl_easy_init() failed\n");
return 1;
}
for (int i = 2; i < argc; i++) {
sprintf(filename, "%s", argv[i]);
fp = fopen(filename, "wb");
if (!fp) {
printf("Error opening file %s\n", filename);
continue;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
printf("File download failed: %s\n", curl_easy_strerror(res));
}
fclose(fp);
}
curl_easy_cleanup(curl);
curl_global_cleanup();
return 0;
}
每个参数都解释如下:
实现步骤: