0% found this document useful (0 votes)
91 views

Downloader

This C program uses the cURL library to download a file from a URL. It prompts the user to enter a URL and filename, initializes a cURL handle, configures the handle with the URL and file pointer, performs the download, and cleans up. It returns an error message if the download fails or a success message if it completes successfully.

Uploaded by

Paritosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Downloader

This C program uses the cURL library to download a file from a URL. It prompts the user to enter a URL and filename, initializes a cURL handle, configures the handle with the URL and file pointer, performs the download, and cleans up. It returns an error message if the download fails or a success message if it completes successfully.

Uploaded by

Paritosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

/*

* A file downloader
* @uthor: PARITOSH KUMAR RAKESH
* DATE: JUL 23 2020
*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <signal.h>
#include <string.h>
#include <libxml/HTMLparser.h>
#include <libxml/xpath.h>
#include <libxml/uri.h>
#include <curl/curl.h>

int main()
{
CURL* curl; //Curl handle for networking
char filename[20];
char url[1000];
system("clear");
printf("URL >>> ");
scanf("%s",&url);
printf("Filename >>> ");
scanf("%s",&filename);
FILE* fp = fopen(filename,"wb");
int result;
curl = curl_easy_init(); //initialise the handle
curl_easy_setopt(curl, CURLOPT_URL, url); //configure the handle to parse the
url
curl_easy_setopt(curl, CURLOPT_ALTSVC, "altsvc.txt");

/* restrict which HTTP versions to use alternatives */


curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, (long)
CURLALTSVC_H1|CURLALTSVC_H2|CURLALTSVC_H3);

curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); //'' to write to a filepointer


curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
result = curl_easy_perform(curl);
if(result == CURLE_OK)
{
printf("\nDownload succes!\n");
}
else
{
printf("ERROR: %s\n",curl_easy_strerror(result));
}
fclose(fp);
curl_easy_cleanup(curl);
return 0;
}

You might also like