textfile to aurduino

i want to send text file to aurduino .

here is the code for it but its not displaying anything, can any one help me?

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

byte mac = { 0x98, 0x4F, 0xEE,0x01, 0x65, 0x4E };
IPAddress ip(192,168,19,170);

char server = “192.168.19.171”;

EthernetClient client;
void setup() {
Serial.begin(9600);
if (Ethernet.begin(mac) == 0) {
Serial.println(“Fail DHCP”);
Ethernet.begin(mac, ip);
}
delay(1000);
Serial.println(“conecting…”);
if (client.connect(server, 80)) {
Serial.println(“connected”);
// Make a HTTP request:
client.println(“GET /mydata.txt HTTP/1.0”);

client.println(“Host:192.168.19.171”);
client.println(“Close”);
client.println();
}
else {
Serial.println(“fail”);
}
}
//loop --------------------------------
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println(“disconecting.”);
client.stop();
while(true);
}
}

client.println("GET /mydata.txt HTTP/1.0");

The GET request identifies a program to run on the server. That does not look like an executable program.

please post you code in

code tags

→ upper left corner of the window looks like </>

To your problem:

You go into an endless while loop if there isn’t a client connected the very second you start your arduino. Why do you do this?

 if (!client.connected()) {
   Serial.println();
   Serial.println("disconecting.");
   client.stop();
   while(true);
 }

PaulS: The GET request identifies a program to run on the server. That does not look like an executable program.

how to modify it?

how to modify it?

With a text editor. The code you have is NOT how to get a file. Something needs to open the file, and stream it's contents back to you. That something is what goes in the GET request. Of course, that something probably wants to know what file you want the contents of. So, your GET request should look like:

client.println("GET /streamFile.php?file=mydata.txt HTTP/1.0");

Then, all you need to do is install PHP on the server, and write the streamFile.php script to open the named file and stream the contents back to you.

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

byte mac[] = { 0x98, 0x4F, 0xEE,0x01, 0x65, 0x4E };
IPAddress ip(192,168,19,170);
                    
   

char server[] = "192.168.19.171/"; 

EthernetClient client;
void setup() {
  Serial.begin(9600); 
 if (Ethernet.begin(mac) == 0) {
   Serial.println("Fail DHCP");
   Ethernet.begin(mac, ip);
 }
 delay(1000); 
 Serial.println("conecting...");
 if (client.connect(server, 80)) {
   Serial.println("connected");
   // Make a HTTP request:
   client.println("GET /def.php?file=mydata.txt HTTP/1.0");
   //client.println("GET localhost/arduino.txt HTTP/1.1");
   client.println("Host:192.168.19.171");
   client.println("Close");
   client.println();
 } 
 else {
   Serial.println("fail");
 }
}
//loop --------------------------------
void loop()
{
 if (client.available()) {
   char c = client.read();
   Serial.print(c);
 }
 if (!client.connected()) {
   Serial.println();
   Serial.println("disconecting.");
   client.stop();
   while(true);
 }
}

below is def.php

abc.txt (350 Bytes)

def.txt (149 Bytes)

Its not showing anything on serial monitor

below is def.php

There are two files attached, neither of which will do what OP wants. The def.txt file is useless.

The abc.txt file is closer, but it expects a POST action to have occurred, not a GET action.

Second, it expects the name, of the name equal value pair after the ?, to be field1, not file.

Third, regardless of what the value in the name equal value pair is, it always sends the same file's contents back, without consideration of where the file is located.

PaulS: There are two files attached, neither of which will do what OP wants. The def.txt file is useless.

The abc.txt file is closer, but it expects a POST action to have occurred, not a GET action.

Second, it expects the name, of the name equal value pair after the ?, to be field1, not file.

Third, regardless of what the value in the name equal value pair is, it always sends the same file's contents back, without consideration of where the file is located.

PaulS: There are two files attached, neither of which will do what OP wants. The def.txt file is useless.

The abc.txt file is closer, but it expects a POST action to have occurred, not a GET action.

Second, it expects the name, of the name equal value pair after the ?, to be field1, not file.

Third, regardless of what the value in the name equal value pair is, it always sends the same file's contents back, without consideration of where the file is located.

i am new to php i just followed one youtube video to create file using php..

so i have to modify those two na?