Send SD Card file through Ethernet

Hi all,

I'm doing a project using an Arduino UNO and a Ethernet w5100 shield.
I want to send a log file stored in SD Card. I thought on make an HTTP Post request to an apache handler which receives the data.

Do you have an example or advice to get this working or some information that could be useful for this feature?


The examples found with the ethernet library are a good place to start.
Getting connection and store some text to a server is most difficult part of your projecy (imho)

For file access check the SD library or the sdfat lib

As the Arduino has only little RAM best you can do is send the data in chunks, e.g. line per line.

Take a look at this example from the playground

Some web server test code that uploads a jpg from the SD card to a requesting browser.

//zoomkat 12/26/12
//SD server test code
//open serial monitor to see what the arduino receives
//address will look like when submited
//for use with W5100 based ethernet shields

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 
  192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString; 


void setup(){


  // disable w5100 while setting up SD
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c =;

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string 
          readString += c; 
        //if HTTP request has ended
        if (c == '\n') {

          Serial.println(readString); //print to serial monitor for debuging 

            client.println("HTTP/1.1 200 OK"); //send new page
          //client.println("Content-Type: text/html");
          client.println("Content-Type: image/jpeg");
          //client.println("Content-Type: image/gif");
          //client.println("Content-Type: application/x-javascript");
          //client.println("Content-Type: text");


          //File myFile ="boom.htm");
          File myFile ="HYPNO.JPG");
          //File myFile ="BLUEH_SL.GIF");
          //File myFile ="SERVOSLD.HTM");

          if (myFile) {

            byte clientBuf[64];
            int clientCount = 0;

              clientBuf[clientCount] =;

              if(clientCount > 63)
                // Serial.println("Packet");
                clientCount = 0;
            //final <64 byte cleanup packet
            if(clientCount > 0) client.write(clientBuf,clientCount);            
            // close the file:
          //stopping client


Maybe this post is old. I managed to upload some files though sockets with Arduino Mega and Ethernet shield, I am not sure if it is useful but I post a link:

Finally there is no good answer for this thread. I'm looking for about a week for this answer and no solution. Does anybody know how to download that log file from SD to PC by clicking a link? This should be simple and already delivered with library but it's not.

"Finally there is no good answer for this thread."

I think you will eventually find your answer on the receiving end, except for maybe sending the appropriate file (MIME) type to the receiving client.