stm32plus::net FTP server module

The File Transfer Protocol (FTP) is one of the oldest application level protocols on the internet. It was originally designed to cater for a wide range of file transfer use-cases including moving files between computers you were not even logged into as well as supporting the needs of arcane mainframe systems.

Today, FTP is still around and one use-case is all-pervasive; that of the FTP server hosting an archive and multiple FTP clients pulling files from that archive.

The classes and templates provided by stm32plus::net support your need to write an asynchronous, multi-client FTP server by taking care of the protocol details internally and deferring to your code when an implementation-specific action is required, such as logging in a user with a supplied name and password.

stm32plus::net only supports passive mode. The original specification that had the FTP client open a server port for data transfer was a security disaster and is not supported.

The net_ftp_server example is a full-featured demonstration that allows you to run an FTP server on your STM32 serving files from an SD card.

Implementation details

FTP is not a module that you include in your stack configuration. It is a set of classes and templates that make it easier for you to write an FTP server.

FTP is built upon the TCP transport. stm32plus::net provides you with an FtpServerConnection template that derives from TcpConnection. You are expected to derive your FTP server connection class from this template. See the MyFtpServerConnection in the net_ftp_server sample for an example.

You will note that the FtpServerConnection template requires the name of your implementation class as one of its template parameters:

class MyFtpServerConnection :
  public FtpServerConnection<MyFtpServerConnection,Tcp<MyNetworkLayer> > {

This is called the Curiously Recurring Template Pattern (CRTP) and is used to achieve static polymorphism avoiding the overhead of virtual function tables. This means that you are required to implement some function calls defined by the base class. Those calls are:

		bool writeGreeting();
		bool writeGoodbye();
		bool isAnonymousPermitted();
		bool hasTimedOut(uint32_t idleMillis) const;
		bool loginUser(const char *user,const char *password);
		bool setCwd(const char *cwd);
		const char *getCwd();
		bool upload(const char *param,bool append,OutputStream*& stream);
		bool download(const char *filename);
		bool simpleListing();
		bool complexListing();
		bool createDirectory(const char *dir,std::string& newdir);
		bool removeDirectory(const char *dir);
		bool removeFile(const char *filename);
		bool fileSize(const char *filename,uint32_t& fileSize);
		bool handleClosed();

The net_ftp_server example implements all of these to provide its SD-based service. See the example code for details. The example has been tested against the latest versions of Internet Explorer, Google Chrome and Mozilla Firefox as well as the Linux and Cygwin command-line clients.