Manage SD files remotely from PC.

riphet:
the standard Arduino Ethernet library does not include the TCP, all is UDP.

I think that conclusion is completely wrong. The Ethernet shield is routinely used to run a web server, which uses HTTP over TCP.

To support FTP you will need to use two TCP connections simultaneously, which might be an issue, but you should certainly be able to establish at least one TCP connection.

Well, I checked the library Ethernet and only see routines UDP.
The IPaddress.h is UDP, the udp.h is udp, all inside the web server is udp.

Anyway: I want to know how to be what you say.
really, I'm interested.

As I said before: am newbie, and an example of the code I need to try again.

riphet:
As I said before: am newbie, and an example of the code I need to try again.

Look at the WebServer example that comes with the Ethernet library. This shows a TCP server - the example supports HTTP, but from the networking point of view an FTP server would be similar.

That is what this thread.

When I change port 80 to port 21,
available function does not capture the client connections.

I mean standard FTP client software.

Of course, I'd like to do this work.
NOT request much.

I stopped by that I can not detect the first client connection.

So I have clear that I start another port from the server to respond.


On the other hand.
Locate a small file name: tcp.c in:
hardware\arduino\firmwares\wifishield\wifiHD\src\SOFTWARE_FRAMEWORK\SERVICES\LWIP\lwip-1.3.2\src\core

would like to know how to use it for a solution.
I'm reviewing.

I am on a very similar project, a minimal ftp server for Due and WIZ820io, for the same reason: I am realizing a mp3 player (see my web page: LaRocola ) and don't want to remove the microSD card from my reader each time I want to update the files.

I had the same problem: function server.available() only return true if, after having connected, the client send at least one character.
And RFC 959 is clear, the sequence for initializing a ftp connection must be in this order:
1- client connect
2- server detect connection
3- server send code 220
4- client send his first command (normally USER)

For me, the fault is of the Ethernet library
How I solve it:
First, try this code (change values of mac and IPAddress variables):

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

byte mac[] = { 0x90, 0xa2, 0xda, 0x00, 0x00, 0x00 };
IPAddress ip( 192, 168, 1, 100 );
EthernetServer ftpServer( 21 );
EthernetServer dataServer( 20 );
EthernetClient client;

void setup()
{
  Serial.begin(9600);
  Serial << "Initiating Ftp Server on Due" << endl;

  // Initialize the network
  //Ethernet.begin( mac, ip, gateway, gateway, subnet );
  Ethernet.begin( mac, ip );
  // Tells the ftp server to begin listening for incoming connection
  ftpServer.begin();

  delay( 2000 );
  Serial << "Ftp server waiting for connection on port 21." << endl;
}

void loop()
{
  // wait for a client to connect
  client = ftpServer.available();
  if( client == true )
  {
    Serial << "Client connected!" << endl;
    client << "220 Welcome to FTP for Arduino\r\n";
    // echo any character send to server for 20 seconds
    int32_t millisEndConnection = millis() + 20 * 1000;
    while( (long) ( millisEndConnection - millis() ) > 0 )
    {
      if( client.available() )
      {
        char c = client.read();
        client << c;
        Serial << c;
      }
    }
    Serial << "Timeout. Disconnecting client" << endl;
    client.stop();
    delay( 1000 );
    Serial << "Ftp server waiting for connection on port 21." << endl;
  }
}

We know it does not work.
Now, close the ide and open the file arduino-1.5.2/hardware/arduino/sam/libraries/Ethernet/EthernetServer.cpp in you editor.
Look at function EthernetServer::available() (on line 51):

EthernetClient EthernetServer::available()
{
  accept();

  for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
    EthernetClient client(sock);
    if (EthernetClass::_server_port[sock] == _port &&
        (client.status() == SnSR::ESTABLISHED ||
         client.status() == SnSR::CLOSE_WAIT)) {
      if (client.available()) {
        // XXX: don't always pick the lowest numbered socket.
        return client;
      }
    }
  }

  return EthernetClient(MAX_SOCK_NUM);
}

The first if statement check for connection on socket sock
The second if statement check for data available for reading on that socket. We must remove it or comment the lignes 60 and 63:

EthernetClient EthernetServer::available()
{
  accept();

  for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
    EthernetClient client(sock);
    if (EthernetClass::_server_port[sock] == _port &&
        (client.status() == SnSR::ESTABLISHED ||
         client.status() == SnSR::CLOSE_WAIT)) {
      // if (client.available()) {
        // XXX: don't always pick the lowest numbered socket.
        return client;
      // }
    }
  }

  return EthernetClient(MAX_SOCK_NUM);
}

Rerun the previous sketch and try to connect with your ftp client. It works for me with FileZila

Of course, modifying the function EthernetServer::available() is not a clean solution. Surely, some programs there where working fine before would fail...

So, instead of modifying that function I add a new one, EthernetServer::connected() :

EthernetClient EthernetServer::connected()
{
  accept();

  for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
    EthernetClient client(sock);
    if (EthernetClass::_server_port[sock] == _port &&
        (client.status() == SnSR::ESTABLISHED ||
         client.status() == SnSR::CLOSE_WAIT))
        return client;
  }

  return EthernetClient(MAX_SOCK_NUM);
}

I repeat: I make this test with the Arduino Due, but I think this is the same problem with others Arduinos.
May be someone can probe it on Mega2560 and/or with others ftp clients.
Remember that libraries for AVR microcontrollers are in arduino-1.x.x/hardware/arduino/avr
Hope this would help

My ftp server is now operational.
Take a look at Ftp Server on Arduino - Networking, Protocols, and Devices - Arduino Forum

Until today I had the opportunity to see your post.

The content of your post is excellent.

I do not yet tests with your proposed.
Reading even with much interest.

At this time I have at hand,
example of code that I received from people of www.wiznet.co.kr.

FTP DAEMON (attach).
I understand it's code written in C
I do not know much, does not work with Arduino IDE.

I seek Now:
Something like your code, but without modification Ethernet.h
Something like this FTP DAEMON samplex C, but with code for arduino IDE.
Something working properly with TCP protocol.

I have no idea how to translate,
from C language for Arduino IDE code.

I appreciate any related information.

now I go to GitHub - gallegojm/Arduino-Ftp-Server: Ftp server for Arduino Due and Ethernet Shield or WIZ820io

ftpd.zip (52.9 KB)

Hi riphet
Happy if my code can help you
Any comment would be welcome