Tag: curl

libcurl – 保持连接“打开”以上传多个文件(FTP)

我需要将目录上传到我的应用程序上的FTP服务器,并计划使用libcurl 。 我看到没有直接的方法来上传包含许多文件的目录,这对我来说很有意义。 但是,我无法在上传许多文件时找到任何提及。 如果我得到目录中的文件列表,我可以在循环中上传它们。 选项CURLOPT_FTP_CREATE_MISSING_DIRS可能有助于子目录,但如果我也想知道我是否错过了这一点,或者这会有任何严重的缺点。 主要问题是:如何保持连接“开放”? 重新连接每个文件可能意味着额外的不必要的开销。 理想情况下,我想继续使用简单的界面。 但是如果在这种情况下另一个接口提供更好的支持,我将使用它。 CURLcode ret; CURL *handle = curl_easy_init(); /* Connect to FTP server using * * the given username and password */ for ({each file}) { curl_easy_setopt(handle, …, …); … ret = curl_easy_perform(handle); /* Analyse return code */ curl_easy_reset(handle); } /* Disconnect from server */ curl_easy_clenup(handle);

libcurl在上传数据之前延迟1秒,命令行curl不会

我正在使用libcurl向本地服务发送API命令(即在127.0.0.1上)。 该程序旨在替换shell脚本(使用curl程序。) 一切都在工作,除了在某处有1秒的延迟,即从我调用curl_easy_perform()到第一次调用我的读回调函数的时间curl_easy_perform() 1秒。 C程序正在使用这些选项(省略错误检查和回调代码): curl_easy_setopt(curl, CURLOPT_URL, “http://127.0.0.1:12345/x”); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long)getLengthOfCommandObject()); curl_easy_setopt(curl, CURLOPT_READFUNCTION, &myReadFunction); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &myWriteFunction); 但是如果我像这样从shell运行curl : $ curl –data-binary ” http://127.0.0.1:12345/x 它会立即发送请求,而不会受到1秒延迟的影响。 可能导致延迟的原因是什么,我可以设置一个防止它的选项吗? 编辑服务器基于mongoose

使用libcurl在PUT请求中发送字符串

我的代码如下所示: curl = curl_easy_init(); if (curl) { headers = curl_slist_append(headers, client_id_header); headers = curl_slist_append(headers, “Content-Type: application/json”); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_URL, “127.0.0.1/test.php”); curl_easy_setopt(curl, CURLOPT_PUT, 1L); res = curl_easy_perform(curl); res = curl_easy_send(curl, json_struct, strlen(json_struct), &io_len); curl_slist_free_all(headers); curl_easy_cleanup(curl); } 哪个不起作用,该程序永远挂起。 在test.php中,这些是我得到的请求标头: array(6) { [“Host”]=> string(9) “127.0.0.1” [“Accept”]=> string(3) “*/*” [“Transfer-Encoding”]=> string(7) “chunked” [“X-ClientId”]=> string(36) “php_…” [“Content-Type”]=> string(16) […]

对于curl程序,获取未定义的引用’clock_gettime’错误

Gretings, 我有交叉编译,OpenSSl,libssh2,最后是cURL,不知道为什么它只生成了静态库。 无论如何,我试图通过链接所有三个库来运行示例ftpget.c程序,但我收到以下错误: …/libcurl.a(timeval.o): In function ‘curlx_tvnow’: timeval.c:(.text+0xfc): undefined reference to ‘clock_gettime’ collect2: ld return 1 exit status make: *** [all] Error 1 请帮我解决这个错误,是否还需要交叉编译其他任何库? 谢谢,Yuvi

尝试使用C访问Twitter Streaming API

我从C libcurl得到了代码输出到字符串 。 我修改了它,我想用它来访问Twitter Stream。 我添加了curl_easy_setopt(curl, CURLOPT_URL, “http://stream.twitter.com/1/statuses/sample.json”); 和curl_easy_setopt(curl, CURLOPT_USERPWD, “neilmarion:my_password”); 在代码中。 但问题是每当我执行它时,都没有输出。 一定是什么问题? 谢谢。 #include #include #include #include struct string { char *ptr; size_t len; }; void init_string(struct string *s) { s->len = 0; s->ptr = malloc(s->len+1); if (s->ptr == NULL) { fprintf(stderr, “malloc() failed\n”); exit(EXIT_FAILURE); } s->ptr[0] = ‘\0’; } size_t writefunc(void *ptr, […]