# Manage SD files remotely from PC.

**URL:** <https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320>\
**Category:** General Guidance\
**Created:** [May 29, 2013, 10:41pm UTC](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320 "2013-05-29T22:41:49Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 2, 2013, 6:00pm UTC](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320/21 "2013-06-02T18:00:11Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![riphet](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@riphet](https://forum.arduino.cc/u/riphet)\
**Post date:** [June 2, 2013, 6:24pm UTC](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320/22 "2013-06-02T18:24:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 2, 2013, 7:03pm UTC](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320/23 "2013-06-02T19:03:45Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![riphet](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@riphet](https://forum.arduino.cc/u/riphet)\
**Post date:** [June 2, 2013, 7:19pm UTC](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320/24 "2013-06-02T19:19:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gallegojm](https://avatars.discourse-cdn.com/v4/letter/g/7ba0ec/32.png) [@gallegojm](https://forum.arduino.cc/u/gallegojm)\
**Post date:** [August 8, 2013, 1:18am UTC](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320/25 "2013-08-08T01:18:12Z")

</div>

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](http://larocola.net/?c=larocola2) ) 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):

```arduino
#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):

```arduino
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:

```arduino
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() :

```arduino
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

---

<div class="post-metadata">

**Author:** ![gallegojm](https://avatars.discourse-cdn.com/v4/letter/g/7ba0ec/32.png) [@gallegojm](https://forum.arduino.cc/u/gallegojm)\
**Post date:** [August 15, 2013, 8:35pm UTC](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320/26 "2013-08-15T20:35:30Z")

</div>

My ftp server is now operational.  
Take a look at [Ftp Server on Arduino - Networking, Protocols, and Devices - Arduino Forum](http://forum.arduino.cc/index.php?topic=182382.0)

---

<div class="post-metadata">

**Author:** ![riphet](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@riphet](https://forum.arduino.cc/u/riphet)\
**Post date:** [October 9, 2013, 10:46am UTC](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320/27 "2013-10-09T10:46:08Z")

</div>

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](http://github.com/gallegojm/Arduino-Ftp-Server)

[ftpd.zip](https://forum.arduino.cc/uploads/short-url/rdryhFkRuqdmgPR4tnDpSJ0e0wl.zip) (52.9 KB)

---

<div class="post-metadata">

**Author:** ![gallegojm](https://avatars.discourse-cdn.com/v4/letter/g/7ba0ec/32.png) [@gallegojm](https://forum.arduino.cc/u/gallegojm)\
**Post date:** [October 9, 2013, 12:53pm UTC](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320/28 "2013-10-09T12:53:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 4:54pm UTC](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320/29 "2021-05-05T16:54:19Z")

</div>

Closed on May 5, 2021, 4:54pm UTC



[Previous page](https://forum.arduino.cc/t/manage-sd-files-remotely-from-pc/165320.md?page=1)
