Thread: How to Download File from Internet by C?

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    17

    How to Download File from Internet by C?

    Hello,

    How can I download file from internet and save in the computer for Windows by C please?

    I googled a bit and all they recommend is libcurl but I could not add libcurl properly for Code::Blocks and Visual Studio.

    Is there anyway I can do this without using libcurl please?

    Cheers

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    120
    Well, I'm no expert in this subject, but doing it from scratch would require knowledge about the protocol you're trying to communicate with to get the data, as well as sockets. These shouldn't be hard to learn, but they are time conssuming to put in practice. I really suggest you try to install a library if you just want to get it done. What problems are you having when installing the library?

  3. #3
    Registered User
    Join Date
    Apr 2015
    Posts
    17
    Quote Originally Posted by shiroaisu View Post
    Well, I'm no expert in this subject, but doing it from scratch would require knowledge about the protocol you're trying to communicate with to get the data, as well as sockets. These shouldn't be hard to learn, but they are time conssuming to put in practice. I really suggest you try to install a library if you just want to get it done. What problems are you having when installing the library?
    Thanks for the reply.

    I see. Actually I wanted to add libcurl to Visual Studio 2013. I found below page from net:

    c++ - Adding CURL Library To Visual Studio 2013 - Stack Overflow

    But the problem linked library is not available any more:

    cURL: win32-ssl-devel-msvc from Mirrors

    I googled a bit but could not find any other source for msvc version and gave up. Wanted to ask here if there is any other way.

    What can I do for the missing msvc library please?

    Cheers

  4. #4

  5. #5
    Registered User
    Join Date
    Apr 2015
    Posts
    17
    Quote Originally Posted by rags_to_riches View Post
    Thank you very much for your help.

    I am totally new to C and desktop programming. Downloaded the 32bit files only version and checked Documentation folder but it seems scary. Any recommendation about how can I use this folder in Visual Studio please?

    Cheers

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    120
    You can just download the .msi installer and select advanced, as stated in the website, to install the dev libraries you need.

  7. #7
    Registered User
    Join Date
    Apr 2015
    Posts
    17
    Thanks @shiroaisu. I downloaded and installed the file with advanced default options.

    Should I expect to use libcurl without any other adjustment in Visual Studio after the installation? Because when I use #include <curl/curl.h> inside a code, it warns me that VS can not find the file or directory. I expected the libcurl headers will be automatically added to system headers but this does not appear to be so. I go back and tried to use the same tutorial again but there is not lib/Release folder under installation folder:

    c++ - Adding CURL Library To Visual Studio 2013 - Stack Overflow

    What would you recommend now please?

    Cheers

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    120
    You probably need to find the folder where the library was installed and add the include/ directory as a compiler search path, and the lib/ directory as a linker search path. I've not used visual studio for ages, so I can't really help you with that part.

  9. #9
    Registered User
    Join Date
    Apr 2015
    Posts
    17
    Quote Originally Posted by shiroaisu View Post
    You probably need to find the folder where the library was installed and add the include/ directory as a compiler search path, and the lib/ directory as a linker search path. I've not used visual studio for ages, so I can't really help you with that part.
    Thansk @shiroaisu again. Yes, I finally could add the include an linker directories.

    I can understand include directory which is for header files. But what is the purpose of this linker directory?

    Also do I need to take these two steps for every external library? Or are the requirements change according to the library properties?

    Cheers

  10. #10
    Registered User
    Join Date
    Mar 2015
    Location
    BE
    Posts
    66
    GNU wget.

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    120
    The linker search path is where the linker searches for libraries you try to link with your program. If you do not include it the linker will not find the library specified and you will get a linker error.

    The library itself is where the linker finds the definitions for external identifiers (variables, functions, etc.). While the header tells the compiler those identifiers exist somewhere, it is the linker's job to decide if they actually exist, and what is their meaning.

    Generally, yes, you do need to take these steps with every library. Each time you download a library you need to add both the path where the headers lie (generally a directory called 'include' in the library's folder), the path where the library itself lies (generally the directory called 'lib' in the library's folder). After that you'll probably need to tell the linker to link with the library you just downloaded.
    Sometimes the same library might even be made up of diferent sublibraries. As an example, there's this library called SDL2 which contains both sdl2_main and sdl2, and keep in mind the linking order can be important due to dependencies. For instance, SDL2 depends on SDL2_main.
    Some libraries might even not be linked at all. They might consist of headers only, and have all their definitions within their headers. This is generally used for small libraries to save the hassle of having to generate libraries and link, which makes the program less portable, or for libraries which declare things inline.

    Anyway, what you need to know about a certain library you'll probably find in the documentation. Try to find files like README or INSTALL or find the manuals online. By doing this you'll also learn how to find those things, and believe me, reading manuals is a 'skill' which is pretty useful outside of programming too. Don't be afraid to read manuals like some people seem to be, they are generally not that big, you'll avoid asking many questions and waiting for many answers, and you'll know how to use the material provided as efficiently as possible. I also recomend you to find something you can use for reference for the libraries you use, so you can quickly lookup a function's header for instance.

    It's amazing how much you can learn from reading a manual.

  12. #12
    Registered User
    Join Date
    Apr 2015
    Posts
    17
    Quote Originally Posted by shiroaisu View Post
    The linker search path is where the linker searches for libraries you try to link with your program. If you do not include it the linker will not find the library specified and you will get a linker error.

    The library itself is where the linker finds the definitions for external identifiers (variables, functions, etc.). While the header tells the compiler those identifiers exist somewhere, it is the linker's job to decide if they actually exist, and what is their meaning.

    Generally, yes, you do need to take these steps with every library. Each time you download a library you need to add both the path where the headers lie (generally a directory called 'include' in the library's folder), the path where the library itself lies (generally the directory called 'lib' in the library's folder). After that you'll probably need to tell the linker to link with the library you just downloaded.
    Sometimes the same library might even be made up of diferent sublibraries. As an example, there's this library called SDL2 which contains both sdl2_main and sdl2, and keep in mind the linking order can be important due to dependencies. For instance, SDL2 depends on SDL2_main.
    Some libraries might even not be linked at all. They might consist of headers only, and have all their definitions within their headers. This is generally used for small libraries to save the hassle of having to generate libraries and link, which makes the program less portable, or for libraries which declare things inline.

    Anyway, what you need to know about a certain library you'll probably find in the documentation. Try to find files like README or INSTALL or find the manuals online. By doing this you'll also learn how to find those things, and believe me, reading manuals is a 'skill' which is pretty useful outside of programming too. Don't be afraid to read manuals like some people seem to be, they are generally not that big, you'll avoid asking many questions and waiting for many answers, and you'll know how to use the material provided as efficiently as possible. I also recomend you to find something you can use for reference for the libraries you use, so you can quickly lookup a function's header for instance.

    It's amazing how much you can learn from reading a manual.
    Thank you so much @shiroaisu for your detailed reply.

    Because I did not know how to include and link, I could not move forward. Now everything is more clear, I will be more keen to read manuals as you sugested.

    Cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Download file from my webserver?
    By Anddos in forum C++ Programming
    Replies: 4
    Last Post: 07-07-2014, 01:06 PM
  2. command to download a file from internet
    By ssharish2005 in forum Tech Board
    Replies: 3
    Last Post: 10-14-2009, 06:23 AM
  3. download a file
    By munna_dude in forum C Programming
    Replies: 1
    Last Post: 05-18-2007, 05:29 AM
  4. Download File
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 02-24-2005, 07:30 AM

Tags for this Thread