Download code

This is a discussion on Download code within the C++ Programming forums, part of the General Programming Boards category; How can I make c++ download something from internet to a folder? I've seen a dll made with c++ what ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Download code

    How can I make c++ download something from internet to a folder? I've seen a dll made with c++ what downloads files but how can I do it?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    it depends on the operating system. "sockets" is a good search term to start with though.
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    There's lotsa ways, you're being incredibly vague. If you're on Windows and want very easy-to-use API's, you might check out the WinInet API with things like InternetReadFile or perhaps URLDownloadToFile. However, I think that connect()ing, send()ing a request and then recv()ing data from the socket would be a perfectly applicable choice for you. You can search the internet for something like a simple HTTP Get, and check out socket FAQ's, read Beej's socket tutorial, etc. I'm sure you'll find something to suit you.

  4. #4
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Can you make me an example of it? Make me an example which dowloads a file to my computer. For example google logo.

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Did you even try to look? An example of what? Okay well, Beej has graciously provided us with a stream socket example. It can be located here: http://www.ecst.csuchico.edu/~beej/g...l#simpleclient of course, this can be modified more than easily to fit winsock and the HTTP protocol. Simply start up winsock (WSAStartup()), and perform a send() of "GET /favicon.ico HTTP/1.1\r\nHost: meh.meh.meh\r\n\r\n" for example, and optionally, you could call inet_addr() before gethostbyname, as it is part of the Winsock Lame List. Again, this is only one example, and you never asked for which one to implement, and are again being vague. If you wanted to use InternetReadFile, look up InternetOpen, InternetOpenUrl, and then ReadFile API reference, it's almost identical in function. If you wanted URLDownloadToFile, well, it's incredibly simple, the callback is somewhat more difficult to implement though. A google search gets plenty of pretty nice results.

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    At least the MSDN function reference didn't explain anything... I dont even know the header file to be included...

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    So I need these headers: <netdb.h> <sys/types.h> <netinet/in.h> <sys/socket.h>
    Where can i get them?

  8. #8
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    You can also use HTTP API
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I looked there and that didnt explain anything

  10. #10
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Maybe you should wait until you know more C++. You're probably wasting time just trying to skip to sockets, as you wont get the full benefit without knowing how to put it together in sensible/efficient ways.

    The comments on the code on those sites is enough explanation needed when you know C++. Since you should know C++ before you move onto sockets it doesnt need to explain much, it just shows you which headers and which commands to use, then you look up the commands somewhere (MSDN, google, etc.) and put them together.

    This is a simple tutorial on Winsocks, sort of like this sites C++ tutorials, so its easier to relate to: http://www.hal-pc.org/~johnnie2/winsock.html
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  11. #11
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    >> You can also use HTTP API

    Yeah I linked to that, it's called the WinInet API. It's kind of a dirty .......... but it's pretty cool I guess. I don't think you really gave a solid attempt to look for resources yourself, but if you want the utter most basic winsock tutorial in the world, MSDN has it, under the name "Getting Started with Winsock". The code is commented, all the functions ref's are linked and explained, and there is simply nothing more complex than a Hello World. Looky here: http://msdn.microsoft.com/library/de...th_winsock.asp
    Last edited by Tonto; 08-22-2005 at 01:25 PM.

  12. #12
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Quote Originally Posted by maxorator
    Can you make me an example of it? Make me an example which dowloads a file to my computer.
    I had to chuckle at your request, maxorator, because what you're asking is a very tall request. It sounds like such a simple little favor, but you're asking for an "example" of something and that something happens to require someone to author the entire body of "your" program's primary functionality.

    You are obviously very new to C++ programming. You really must learn and familiarize yourself with the language and it's concepts before you jump into something as complicated as socket programming. However, if you insist on persisting, do a lot of reading to earn a better comprehension before you jump into the icy waters. Good luck.

  13. #13
    Banned
    Join Date
    Jun 2005
    Posts
    594

    that good link! thanks

  14. #14
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by LuckY
    I had to chuckle at your request, maxorator, because what you're asking is a very tall request. It sounds like such a simple little favor, but you're asking for an "example" of something and that something happens to require someone to author the entire body of "your" program's primary functionality.

    You are obviously very new to C++ programming. You really must learn and familiarize yourself with the language and it's concepts before you jump into something as complicated as socket programming. However, if you insist on persisting, do a lot of reading to earn a better comprehension before you jump into the icy waters. Good luck.
    I don't want to use it in any program, I just want to know how its done.

  15. #15
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by Tonto
    >> You can also use HTTP API

    Yeah I linked to that, it's called the WinInet API. It's kind of a dirty .......... but it's pretty cool I guess. I don't think you really gave a solid attempt to look for resources yourself, but if you want the utter most basic winsock tutorial in the world, MSDN has it, under the name "Getting Started with Winsock". The code is commented, all the functions ref's are linked and explained, and there is simply nothing more complex than a Hello World. Looky here: http://msdn.microsoft.com/library/de...th_winsock.asp
    Ok, first error
    [Linker error] undefined reference to `WSAStartup@8'
    Another error
    4 C:\Programs\Dev-Cpp\Templates\main6.cpp `main' must return `int'
    Last edited by maxorator; 08-22-2005 at 11:45 PM.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Is this right?(about a class) (code to download) etc..
    By knave in forum C++ Programming
    Replies: 0
    Last Post: 07-07-2003, 07:53 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-15-2002, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21