WiFi card drops connection

I am using an Arduino WiFi shield model WIFI R3, and I have updated the firmware in my WiFi card. "Serial.println(WiFi.firmwareVersion());" prints out 1.1.0.

I am using an Arduino to collect data and save it to an SD card. Periodically, the arduino connects to a server (RaspberryPi running Python) and downloads the data saved on the SD card. The sample code I am using to illustrate the problem is (already connected to the network before this point):

void SendFile() {

File myFile;
byte Buffer[32];
long int bytesSent = 0;
  //Open the file to send
myFile = SD.open("datalog.txt");

  if (client.connect(server, Port)) {
    //Start sending data from file to server
    while (myFile.available()) {
      int n = myFile.read(Buffer, 32);  //multiple byte read
      if (status == WL_CONNECTED) {
        if (client.connected()) {
          bytesSent += n;
          Serial.print("Sent bytes: "); Serial.println(bytesSent);
        } else {
          Serial.println("Connection to server was lost");
      } else {
        Serial.println("WiFi connection lost");
    }  //end of while (myFile.available())
    //Send the "#" symbol to tell server end of data

  } else { //end of if client.connect() - did not connect to client
    Serial.println(F("Could not connect to server"));


The first problem I am having is that the WiFi card almost invariably drops the connection to the server before reaching the end of the file (the file I am using to test is about 50kb) and I get the "Connection to server was lost." message from the code above. It is still connected to the wireless network, it is simply dropping the connection to the server. If it helps, the red ERROR light on the WiFi shield comes on briefly when the connection is dropped.

The second issue is that the WiFi card appears to be buffering the data and then sending it when it has ~1024 bytes to send. I say this because when I look at the output from the code above on the serial monitor, I will quickly get to "Sent bytes: [1024]", then a pause, then very quickly get to "Sent bytes: [2080]", another pause, then very quickly to "Sent bytes: [3232]", etc. The issue here is that if I am lucky enough to get to the end of the file, the last bit of data including the '#' which tells the server the transfer is complete never gets sent - presumably because the buffer isn't full?

Has anyone else encountered these problems/is there a problem with my code that could be creating them? I tend to suspect that I am overrunning the buffer on the WiFi shield, although adding a delay(100) after the "client.write(Buffer,n);" statement doesn't seem to help. I have also played around with different buffer sizes with no luck. Finally, I don't believe the error is on the server side since I can write a Python program that replicates what the arduino is doing and it executes with the server very reliably.

Thank you in advance for any assistance!