Project - Stable FTP Server

It’s not a problem of active or passive. I think my understanding of passive and active was the correct one.

I mean 18kB/s! :smiley:

upper case B is for byte minor case is for bit.

Yep I will try to tune the memorychunks and see what’s happened

@ leforban - Then you should be happy. Jeffan (post #7) reported of 1 MegaByte in 350 seconds, which is about 3 kiloByte/sec. If you have 18kB/s you are 6 times as fast and ready with your 3MB file in about 166 seconds. At least remarkable. Vive la difference! :smiley:

1 Like

18kB/s is not fast at all compared to udp transfert even if I know that udp is a lighter protocol, I hope there’s still some space for further improvements

Sure, 18 kB/s is terrible slow. But I think the bottleneck is, where you fetch the data from the e.g. Ethernet module with the NETMF Device. If other threads take their dispatcher timeslice of 20 ms you can have max. 50 actions per second of reading from the Ethernet device. Then the size of the chunks of data read with one action must be responsible for the possible data rate. With a chunk size of 500 bytes you can have max. 25 kB/s, with a chunk size of 2000 bytes 100 kB/s. Here I would search for the screws to enhance speed.

You’re right I understand your point. I have no other explicit thread. Only a big loop where I am not supposed to sleep.
The ftp thread sleep only for a single millisecond to let the big loop running.
I deleted the thread.sleep(1) of the ftp server to see if it was better but without results

maybe you can try this:
put your code in a thread and set it’s priority to highest and see if that makes a difference.


thread.Priority = ThreadPriority.Highest; 

Source: a great article to ready :slight_smile:

Jay.

Hi everyone I have one trouble using the ftpserver. If I disconnect the cable I got the following exception:

[quote]Cable disconnected event
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (9) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::poll [IP: 0000] ####
#### System.Net.Sockets.Socket::Poll [IP: 0011] ####
#### System.Net.Sockets.Socket::Accept [IP: 0017] ####
#### FtpServer.FtpListenerManager::WorkerThread [IP: 009c] ####
#### SocketException ErrorCode = 10050
#### SocketException ErrorCode = 10050
Une exception de première chance de type ‘System.Net.Sockets.SocketException’ s’est produite dans Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10050
#### SocketException ErrorCode = 10050[/quote]

The handler is as follow:

 void ebi_CableConnectivityChanged(object sender, EthernetBuiltIn.CableConnectivityEventArgs e)
        {
            if (ebi.IsCableConnected)
            {
                Debug.Print("Cable connected event");
                cable_connected = true;
                close_udp_socket();
                launch_udp_socket();
                FtpListener.AuthenticationEvent += FtpListenerOnAuthenticationEvent;
                Debug.Print("Setup FTP Listeners");
                fsRoot = new FtpFilesystemListener("/SD/", @ "\SD", true);
                fsRoot.Start();
                virtualRoot = new FtpVirtualListener("/VirtualRoot/", true);
                virtualRoot.Start();

            }
            else
            {
                Debug.Print("Cable disconnected event");
                close_udp_socket();
                cable_connected = false;
                FtpListener.AuthenticationEvent -= FtpListenerOnAuthenticationEvent;
               }
        }

How to handle the ftpserver disconnection properly?

If you close a tcp listener socket, which waiting for an client (in Accept), then Accept is throwing this exception. This is absolutely normal.
All you need to do is catch this exception, and on reconnect you initialize the FTP server again.

Hello Reinhard, I have made some changes to catch the exception. All works great now. Thanks for your help.

Still have to see how to improve throughput.

I still have a problem with the server that I don’t know how to solve.

In some case I would like to initialize the ftp server (after cable disconnect/reconnect or address changes for example). I have try to call the Stop and start method but stop fires exception and I can’t start the server anymore.

here are the exceptions:

Disconnect and connect cable is something I want to look into in the future.
So far I simply assume that no one would open our cabinet and pull of the cable :whistle:

@ Reinhard Ostermeier - Hi Reinhard, did you already adapt your FTP Server to NETMF 4.3 or do you plan to do this in the future?

the server is 4.3 compliant the only thing that seems not working is the ftplinstener.stop method. In 4.2 exception was launched while stopping but the start was not fail after

Thanks

In 4.2 exceptions are launched but this seems not be a problem.

In 4.3 when trying to (re)start the listener, the 10048 error code is launched. This indicates that the address is already in use. while it should have been stopped just before

I use it in 4.3 without any code modifications.
But I never dived into reconnect of cable, so this might not work property.

And can you stop and start the server without disconnecting the cable?

I’m not sure.
I think I tried it once.
And of course: I always catch and ignore any exceptions on stop and cleanup code :smiley: