How difficult would this be - download and read file

This is a discussion on How difficult would this be - download and read file within the C Programming forums, part of the General Programming Boards category; Hi, Just to set the scene, currently a CSV file is stored in the same directory as the exe file. ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    93

    How difficult would this be - download and read file

    Hi,

    Just to set the scene, currently a CSV file is stored in the same directory as the exe file. When the file is executed it reads the values from the CSV file and displays them.

    How difficult would it be to instead go to a webaddress for the csv file. An example is to download the csv file from www.xxx.com/file.csv, and then read from it in the same way as the previous program. Im assuming this is all possible. If it isnt too hard, can someone please point me in the direction of a function that will make it possible.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,257
    Using libcurl would probably be the easiest way.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    93
    Are there no functions in defalt C to do this without having to use a library like the one you suggested?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,257
    Nothing in standard C. In fact, standard C doesn't even have the capability to open a socket, let alone download a file over the HTTP protocol.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Remember, in order to do this you have to go through the web server that your browser would connect to. There is no other way (in any language). So, to give you an idea of how hard this is, consider the steps
    1. set up an internet domain socket
    2. attempt to connect to the domain server
    3. send a GET request for the file
    4. parse the contents of the HTTP reply from the server
    5. turn the data extracted from the reply back into a file

    It is more than a hundred lines of code, however you cut it. Network packets are layered and require work to dissemble and understand.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Remote file open & read
    By major9 in forum C Programming
    Replies: 3
    Last Post: 04-24-2009, 05:12 AM
  2. file download through ftp using C under Unix
    By Mohit_t in forum C Programming
    Replies: 3
    Last Post: 06-12-2008, 03:00 PM
  3. Read file name?
    By xxxrugby in forum C Programming
    Replies: 2
    Last Post: 03-29-2005, 02:48 PM
  4. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 06:31 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM

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