FTP Server Deinitialization in RTOS Environment

Dear RTOS Team,

I hope this message finds you well. I am reaching out to seek guidance on the proper procedure for deinitializing the FTP server module within our real-time operating system (RTOS) environment, version 15.83.200.

Recently, we encountered challenges while attempting to gracefully shut down the FTP server component. Despite our efforts to deinitialize it using various functions such as FREERTOS_FD_CLR(), FreeRTOS_shutdown(), FreeRTOS_Closesocket(), and FreeRTOS_DeleteSocketSet(), we encountered a hard fault error after only two downloads.

To ensure the correct and efficient handling of this process, I would appreciate your insights on the following points:

  1. Deinitialization Process: Could you please provide detailed instructions or guidelines on how to properly deinitialize the FTP server module? This includes any necessary cleanup tasks, resource release procedures, or specific functions to call.

  2. Error Handling and Recovery: What are the recommended practices for error handling and recovery during the FTP server deinitialization process? In case of any unexpected errors or failures, how should we handle them to maintain system stability and integrity?

  3. Testing and Verification: Finally, could you suggest any testing or verification procedures to validate the correct deinitialization of the FTP server? This may include functional testing, integration testing, or any specific test cases to ensure the reliability of the deinitialization process.

Your expertise and guidance on these matters would be invaluable to us as we strive to ensure the smooth operation and maintenance of our RTOS-based systems.

Thank you for your attention to this inquiry. I eagerly await your prompt response and assistance regarding the FTP server deinitialization process.

With gratitude,
Harish Yadav

The questions you ask are very application specific and would depend on the FTP server code. Where did you get this FTP server code?

Hello @aggarg GauravAggarwal
Thanks for responding.

The code which we are using is taken from FreeRTOS code itself.

FreeRTOS+TCP V2.0.3 This is the version number.

FreeRTOSv202212.01\FreeRTOSv202212.01\FreeRTOS-Plus\Demo\Common\Demo_IP_Protocols\Common\FreeRTOS_TCP_server.c This is the path of file.

FreeRTOS_CreateTCPServer using this function we are creating the server.

Hello @HarishYadav, thanks for your interest in FreeRTOS and its libraries.

The FTP and HTTP servers are supposed to be started at boot time and run until power-down or until a restart.

Why would you want to deinitialise the FTP server?

Individual FTP sessions are stopped (and deinitialised) automatically.

But if you want the stop the service, some extra code will be needed.

Hello @htibosch , thanks for responding.

What you are telling is absolutely right, with respect to FTP and HTTP.

But, In our application, we only open ports based on the enabled protocol. However, in this case, FTP is always open, which poses a security vulnerability.

So, we don’t want to launch FTP server unless it is enabled from our application.

When you say “it is enabled from our application”, do you mean it is a compile time config or a run time config? In either case, you can decide not to call FreeRTOS_CreateTCPServer if you do not wan to launch the server. Does that not work?

In our application, which is a PLC application, the protocol should be launched or disabled based on the user configuration that is downloaded.

And, as you mentioned, we are able to decide not to call FreeRTOS_CreateTCPServer when FTP is not configured from our application. However, once it is configured and downloaded to the PLC, the server remains open even if the next download occurs without configuration. FTP server will continue to operate until the device is powered off.

I see - now I understand your problem. And reboot is not an option for you?

1 Like

Yes, exactly.

I am thinking of making a minor change to the servers: a switch that determines if connections are accepted or not.

In that way, it will start up in the “switched off mode”. As soon as you need it, you can switch it on and users get access to FTP.

Would that solve your problem?

Note that the maximum number of users is guarded by the library.
Note the parameter “backlog” here:

static const struct xSERVER_CONFIG xServerConfiguration[] =
    #if ( mainCREATE_HTTP_SERVER == 1 )
        /* Server type, port number,  backlog, root dir. */
        { eSERVER_HTTP, 80,           12,    configHTTP_ROOT },

    #if ( mainCREATE_FTP_SERVER == 1 )
        /* Server type, port number, backlog,  root dir. */
        { eSERVER_FTP,  21,          12,       ""      }

@htibosch Thanks for the input.
i will test this and come back in a week.