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
BGOFFICE-DICT-DOWNLOAD(1)				User Contributed Perl Documentation				 BGOFFICE-DICT-DOWNLOAD(1)

NAME
bgoffice-dict-download - download dictionaries for bgoffice SYNOPSIS
# list known dictionaries bgoffice-dict-download --list # download a dictionary bgoffice-dict-download --dict bg-en_dual # explicit output file bgoffice-dict-download --dict bg-en_dual --output=/some/where.tar.bz2 DESCRIPTION
bgoffice-dict-download is a small program to help download bgoffice dictionaries off sourceforge.net. It browses the bgoffice project download area and follows the download links. The dictionary is downloaded in the current directory, unless the "--output" option is used. OPTIONS
--list Prints the list of the known dictionaries. --dict dictionary name Specifies the dictionary to be downloaded. See "--list" for the known dictionaries. This option is mandatory, unless "--list" is given. --output file Saves the downloaded dictionary in the given file, instead of ./<dict>.tar.bz2 COPYRIGHT AND LICENSE
Copyright: (C) 2010 Damyan Ivanov dmn@debian.org Permission is granted to use this work, with or without modifications, provided that this notice is retained. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return. perl v5.14.2 2010-12-16 BGOFFICE-DICT-DOWNLOAD(1)
All times are GMT -4. The time now is 05:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy