Libcurl - Progress Data


 
Thread Tools Search this Thread
Top Forums Programming Libcurl - Progress Data
# 1  
Old 05-16-2007
Question Libcurl - Progress Data

Hi,

I codding a download manager,use libcurl library.i can download any file easily.But i want to show file detail in console.Some of them,
  • File Size
  • Percent
  • Left Time

Libcurl has some functions to use,but there isnt good documentation to understand them. i cant find any example to understand.Please help me,Thank you.

Caner Bulut
# 2  
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
# 3  
Old 11-04-2008
ftp upload using curllib

hello
hi facing problem since 6days to geeting upload a file to ftp server.
pls anyone have source code
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. 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

2. 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

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. 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

5. 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
Login or Register to Ask a Question