Go Down

Topic: FTP Server with Arduino Uno + Wiznet (Read 9862 times) previous topic - next topic

AJoao

Hi,
I want to make a FTP Server with Arduino Uno and Ethernet Shield Wiznet, but I didnt discovery yet some example code in the Internet.
I got an example code to FTP Client on this link: http://playground.arduino.cc//Code/FTP, but I dont know make de changes to FTP Server...
On FTP Server I dont put this code?:
      // change to your server
      IPAddress server( 1, 2, 3, 4 );
Somebody can help me please?
Thank you in advance!
Best regards,

AJoao


pylon

FTP is a very old protocol and not really well suited for an embedded platform like the Arduino. Active mode FTP is prohibited by most firewalls today and passive mode means a constant redefinition of the server port. Although this is theoretically possible it doesn't make sense because we have modern protocols like HTTP which does the same as FTP plus a lot more.
So if you really must support FTP as a server on the Arduino, you probably have to program it from scratch, I doubt there will be an already existing implementation. You'll find the specification here http://www.ietf.org/rfc/rfc959.txt

SurferTim

I agree with pylon, with one exception. The HTTP protocol is ok for downloading files from a server to the Arduino client, but to upload a file from the client to the server, I use FTP. That is why the playground sketch is FTP passive client.

The FTP passive server code was a bit too much for me. It requires two server sockets, and managing that with the ethernet library was not really practical. It is difficult enough with two client sockets.

AJoao

Thank you very much!
I go to use HTTP protocol because it is ok for downloading files from a server to the Arduino client.
I go to try make my project with a WebClient.
Best regards,

AJoao

gallegojm

I have a ftp server operating on Arduino, though still incomplete.
Take a look at http://forum.arduino.cc/index.php?topic=182382.0

MarlonVets

#5
Apr 17, 2014, 01:04 am Last Edit: Apr 17, 2014, 01:30 am by MarlonVets Reason: 1
Just wanted to know if anyone found a way to download files from a server to the arduino SD card using HTTP yet. Please let me know, working on a project that requires this feature, i only need to transfer one specific text file after it is updated. Any ideas on how i could achieve this?
I am working with Arduino Uno and Ethernet shield with a 2Gb Sd card text file is about 500kb Max.

I tried using the PUT method with the TinyWebserver here https://github.com/ovidiucp/TinyWebServer
no luck..... it does not respond to the request

This is the upload form used i got it from an example online............
NOTE: not good at programming....... practically at coding for dummies stage

Code: [Select]

<html>
<head>
<title>Upload</title>

<script language="VBSCRIPT">dim strURL
Function sendit(sfileName, sType)
sData = getFileBytes(sfileName, sType)
'MsgBox(sData)
sfileName= mid(sfileName, InstrRev(sFileName,"\")+1, len(sfileName))
dim xmlhttp
set xmlhttp = Createobject("MSXML2.XMLHTTP.3.0")
'strURL = "./" & sfileName
xmlhttp.Open "PUT", strURL, false
xmlhttp.Send sData
show.innerText= "Status: " & xmlhttp.statusText
show1.innerText= "Response: " & xmlhttp.responseText
set xmlhttp=Nothing
MsgBox("Done!! File Uploaded Successfully.")
End Function Function Send(sfileName, sType)
sData = getFileBytes(sfileName, sType)
'MsgBox(sData)
sfileName = mid(sfileName, InstrRev(sFileName,"\")+1, len(sfileName))
End FunctionSub showresult()
document.write "<CENTER>Take A look!<BR/><A href=" & strURL & ">" & URL & "</a></CENTER>"
End SubFunction getFileBytes(flnm, sType)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
if sType="on" then
objStream.Type = 1 ' adTypeBinary
else
objStream.Type = 2 ' adTypeText
objStream.Charset ="ascii"
end if
objStream.Open
objStream.LoadFromFile flnm
if sType="on" then
getFileBytes = objStream.Read
else
getFileBytes = objStream.ReadText
end ifobjStream.Close
Set objStream = Nothing
End Function</script>
</head>
<body><form name="frmUpload" action="" method="POST">
<!--WIRE FRAME DESIGN START-->
<table align="center">
<tr>
<td>
<input type="FILE" id="filedata"></td>
</tr>
<tr>
<td>
<input type="Button" value="Submit" onclick="Call sendit(filedata.value, filetype.value)"></td>
</tr>
<tr>
<td>
<input type="checkBox" id="filetype" checked>Type Binary (Uncheck for Type Text)</td>
</tr>
<tr>
<td>
<input type="button" value="SHOW IT" onclick="showresult()"></td>
</tr>
<tr>
<td>
<div id="show" align="center">
</div>
</td>
</tr>
<tr>
<td>
<div id="show1" align="center">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>




pylon

Quote
Just wanted to know if anyone found a way to download files from a server to the arduino SD card using HTTP yet. Please let me know, working on a project that requires this feature, i only need to transfer one specific text file after it is updated. Any ideas on how i could achieve this?


The WebClient example is exactly doing that just not saving it to the SD card. Combine that with ReadWrite example from the SD library and you have your solution.

Quote
I tried using the PUT method with the TinyWebserver here https://github.com/ovidiucp/TinyWebServer
no luck..... it does not respond to the request


If you want to get a file and store it on the Arduino's SD card, you don't need a web server but a client (the server is serving it and not consuming).

MarlonVets

never thought of that, thank you. Will try and get back to you.

MarlonVets

Well this is what i came up with tried to test it with a local xampp page but it didnt work So just asking you for go through to check if i have the right idea.
Code: [Select]

/*
  Web client

This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield.

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13

created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen

*/

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

File myFile;

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0x07, 0xB8 };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "127.0.0.1";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(169, 254, 144, 105);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /upload.txt HTTP/1.1");
    client.println("Host: 127.0.0.1");
    client.println("Connection: close");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    while(client.available()) {
      char c = client.read();
      myFile = SD.open("test.txt", FILE_WRITE);
      if (myFile) {
        Serial.print("Writing to test.txt...");
        myFile.println(c);
        Serial.print(c);
      }
      myFile.close();
    }
  }
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing forevermore:
    while(true);
  }
}


pylon

127.0.0.1 is the localhost address of your PC. You cannot access that IP from the Arduino.

Put the Arduino in your LAN, let it configure by DHCP and connect to www.google.com for the test. That's probably much easier than setting up a local web server to test with.

MarlonVets


Go Up