Sponsored Content
Full Discussion: Libcurl - Progress Data
Top Forums Programming Libcurl - Progress Data Post 302119046 by canerbulut on Sunday 27th of May 2007 05:03:17 AM
Old 05-27-2007
MySQL

i solve the problem and want to share with you.


#include <stdio.h>
#include <pthread.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

struct FtpFile {
char *filename;
FILE *stream;
};

double *Bar;

int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out=(struct FtpFile *)stream;
if(out && !out->stream) {
/* open file for writing */
out->stream=fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure, can't open file to write */
}
return fwrite(buffer, size, nmemb, out->stream);
}

size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
return fread(ptr, size, nmemb, stream);
}



int progress_callback( char *Bar,double t,double d,double ultotal,double ulnow)
{
printf("deneme : %f \n",d/t*100);
return 0;
}

void thred(char *url)
{
CURL *curl;
CURLcode res;
struct FtpFile ftpfile={
"curl.tar.gz",
NULL
};


curl_global_init(CURL_GLOBAL_DEFAULT);

curl = curl_easy_init();
if(curl) {
// printf("%s Indiriliyor...\n",url);
curl_easy_setopt(curl, CURLOPT_URL,url);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);

if(CURLE_OK != res) {
/* we failed */
fprintf(stderr, "curl told us %d\n", res);
}
}

if(ftpfile.stream)
fclose(ftpfile.stream); /* close the local file */

curl_global_cleanup();

return 0;
}



int main( int argc,
char *argv[] )
{

pthread_t tid[25];
int error,t_count=0,temp_count=0;
int a=0,sabit=0,i=0;
char *dosadi[5];
dosadi[1]="ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.9.2.tar.gz";
dosadi[2]="ftp://ftp.tugraz.at/mirror/devil-linux/devel/sources/1.0/cipe-1.5.4.tar.gz";
dosadi[3]="ftp://ftp.gnu.org/gnu/bash/bash-1.14.7.tar.gz";
dosadi[4]="ftp://ftp.keystealth.org/pub/gnu/gnu/gnu.ps.gz";
dosadi[5]="ftp://ftp.tugraz.at/mirror/devil-linux/devel/sources/1.0/attr-2.4.8.src.tar.gz";


for(i=1; i<=5; i++)
{
error = pthread_create(&tid[i],
NULL,
thred,
dosadi[i]);
}
//
for(i=1; i<=5; i++) {
error = pthread_join(tid[i], NULL);
fprintf(stderr, "Thread %d Yokedildi.\n", i);
}

}


Regards
Caner
 

5 More Discussions You Might Find Interesting

1. Programming

Multithread,libcurl

Hi i m codding a programm,it can download any packet from ftp,I use libcurl library. But i want to use threads for downloading.(Multithreading).i cant get ftp file size from ftp and divide packet small pieces,like threads use. Please share your experince with me ,thanks. (0 Replies)
Discussion started by: canerbulut
0 Replies

2. Shell Programming and Scripting

pass curls progress/status data to a file

hello hackers again. please help me out once again. i have a script which executes CURL to fetch a file from the web and instantly outputs the files content to STDOUT. now my question - can i somehow write the progress-status to a file? so that curl acts silently (-s) and only puts... (0 Replies)
Discussion started by: scarfake
0 Replies

3. Programming

libcurl multi interface problem

Hello, I'm trying to use libcurl multi interface to fetch several data in parallel. I would expect this to be faster than performing repeated fetches using the easy interface, but for some reason I can't obtain any speed up at all: using the multi interface actually turns out to be MUCH slower than... (2 Replies)
Discussion started by: clalfa
2 Replies

4. Programming

libcurl - how to do GET form posting in C?

Hi, I'm learning libcurl so that I can use it in my GTK+/C program and went through the tutorial and code samples but it has only mentioned about POST form as the site I'm using has the GET form and only thing I found googling was using the command in xterm which I don't want. I would be very... (1 Reply)
Discussion started by: jaeezzy
1 Replies

5. Red Hat

libcurl.so.4 problem

libcurl.so.4: cannot open shared object file: No such file or directory ERROR: Loading network library (net.so) failed! Press Q to shut down the server! http://a1108.hizliresim.com/11/8/17/8183.jpg What must I do ? :wall: (14 Replies)
Discussion started by: Stark0010
14 Replies
CURLINFO_FILETIME(3)					     curl_easy_getinfo options					      CURLINFO_FILETIME(3)

NAME
CURLINFO_FILETIME - get the remote time of the retrieved document SYNOPSIS
#include <curl/curl.h> CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_FILETIME, long *timep); DESCRIPTION
Pass a pointer to a long to receive the remote time of the retrieved document (in number of seconds since 1 jan 1970 in the GMT/UTC time zone). If you get -1, it can be because of many reasons (it might be unknown, the server might hide it or the server doesn't support the command that tells document time etc) and the time of the document is unknown. Note that you must tell the server to collect this information before the transfer is made, by using the CURLOPT_FILETIME(3) option to curl_easy_setopt(3) or you will unconditionally get a -1 back. PROTOCOLS
HTTP(S), FTP(S), SFTP EXAMPLE
curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, url); /* Ask for filetime */ curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); res = curl_easy_perform(curl); if(CURLE_OK == res) { res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); if((CURLE_OK == res) && (filetime >= 0)) { time_t file_time = (time_t)filetime; printf("filetime %s: %s", filename, ctime(&file_time)); } } /* always cleanup */ curl_easy_cleanup(curl); } AVAILABILITY
Added in 7.5 RETURN VALUE
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. SEE ALSO
curl_easy_getinfo(3), curl_easy_setopt(3), libcurl 7.54.0 April 03, 2017 CURLINFO_FILETIME(3)
All times are GMT -4. The time now is 09:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy