Synergy Software Package User's Manual
NetX/NetX Duo FTP Server

NetX/NetX Duo FTP Server Introduction

The File Transfer Protocol (FTP) is a protocol designed for file transfers. FTP utilizes reliable Transmission Control Protocol (TCP) services to perform its file transfer function. The actual FTP file transfer is performed on a dedicated FTP connection.

Note
The NetX™ FTP Server module is specific to IPv4. The NetX Duo™ FTP Server module accommodates both IPv4 and IPv6 networks. IPv6 does not directly change the FTP protocol, although some changes in the original NetX FTP APIs are necessary to accommodate IPv6 and will be described in this document.

Unsupported Features

Passive transfer mode has not been tested for NetX in this version of SSP.

NetX/NetX Duo FTP Server Module Features

  • NetX is IPv4 specific
  • NetX Duo supports both IPv4 and IPv6 networks
  • Works with FileX® file system
  • No limit to file name size; uses NULL terminated ASCII strings
  • Supports TCP port 21 to field client requests
  • Provide high-Level APIs for creating, starting, stopping and deleting service
  • NetX FTP and NetX Duo FTP are compliant with RFC 959, RFC 2428 and related RFCs.
nx_ftp_server_BD.png
NetX/NetX Duo FTP Server Module Block Diagram
Note
In the figure above, the FileX and NetX (or NetX Duo) Network Driver modules have multiple implementation options available. See the descriptions just after the module stack figure in Including the NetX/NetX Duo FTP Server Module in an Application for additional details.

NetX/NetX Duo FTP Server Module APIs Overview

The NetX FTP Server defines APIs for creating, deleting, starting and stopping service. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.

NetX/NetX Duo FTP Server Module API Summary

Function Name Example API Call and Description
nx_ftp_server_create nx_ftp_server_create(&my_server, "My Server Name", &ip_0, &ram_disk, stack_ptr, stack_size, &pool_0, my_login, my_logout);
Create FTP Server with IPv4 support only.
**nxd_ftp_server_create nxd_ftp_server_create(&my_server, "My Server Name", &ip_0, &ram_disk, stack_ptr, stack_size, &pool_0, my_duo_login, my_duo_logout);
Create FTP Server with IPv4 and IPv6 support.
nx_ftp_server_delete nx_ftp_server_delete(&my_server);
Delete FTP Server.
nx_ftp_server_start nx_ftp_server_start(&my_server);
Start FTP Server.
nx_ftp_server_stop nx_ftp_server_stop(&my_server);
Stop FTP Server.
Note
For details on operation and definitions for the function data structures, typedefs, defines, API data, API structures and function variables, review the associated Azure RTOS User's Manual in the References section.

**This API is only available in NetX Duo FTP Client. For definitions of of NetX Duo specific data types, see the NetX Duo User Guide for the Renesas Synergy™ Platform.

Status Return Values

Name Description
NX_SUCCESS Successful FTP server function.
NX_PTR_ERROR Invalid FTP pointer.
NX_CALLER_ERROR Invalid caller of this service.
Note
Lower-level drivers may return common error codes. See SSP User's Manual API References for the associated module for a definition of all relevant status return values.

NetX/NetX Duo FTP Server Module Operational Overview

Because FTP Client and Server operations are so closely linked, the following descriptions cover key elements of both Client and Server operations.

FTP Requirements

The NetX FTP package requires NetX or NetX Duo for proper operation. The host application must create an IP instance for running NetX services and periodic tasks. If running the FTP host application over an IPv6 network, IPv6, and ICMPv6 must be enabled on the IP task. TCP must be also enabled for either IPv6 or IPv4 networks. The IPv6 host application must set its linklocal and global IPv6 address using the IPv6 API and/or DHCPv6.

The FTP Server and Client are also designed to work with the FileX embedded file system. If FileX is not available, the host developer can implement or substitute their own file system along the guidelines suggested in filex_stub.h by defining each of the services listed in that file. This is discussed in later sections of this guide.

The FTP Client portion of the NetX FTP package has no further requirements.

The FTP Server portion of the NetX FTP package has several additional requirements. It requires complete access to TCP well-known port 21 for handling all Client FTP command requests and well-known port 20 for handling all Client FTP data transfers.

FTP File Names

FTP file names should be in the format of the target file system, usually FileX. They should be NULL terminated ASCII strings, with full path information if necessary. There is no specified limit for the size of FTP file names in the NetX FTP implementation. The packet pool payload size should be able to accommodate the maximum path and/or file name.

FTP Client Commands

The FTP has a simple mechanism for opening connections and performing file and directory operations. There is a set of standard FTP commands that are issued by the Client after a connection has been successfully established on the TCP well-known port 21. The following table shows some of the basic FTP commands. Note that the only difference when FTP runs over IPv6 is that the PORT command is replaced with the EPRT command:

FTP Server Commands

FTP Command Meaning
CWD path Change working directory
DELE filename Delete specified file name
EPRT ip_address, port Provide IPv6 address and Client data port
LIST directory Get directory listing
MKD directory Make new directory
NLST directory Get directory listing
NOOP No operation, returns success
PASS password Provide password for login
PORT ip_address,port Provide IP address and Client data port
PWD path Pickup current directory path
QUIT Terminate Client connection
RETR filename Read specified file
RMD directory Delete specified directory
RNFR oldfilename Specify file to rename
RNTO newfilename Rename file to supplied file name
STOR filename Write specified file
TYPE I Select binary file image
USER username Provide username for login

These ASCII commands are used internally by the NetX FTP Client software to perform FTP operations with the FTP Server.

FTP Server Responses

Once the FTP Server processes the Client request, it returns a 3-digit coded response in ASCII followed by optional ASCII text. The numeric response is used by the FTP Client software to determine whether the operation succeeded or failed. The following list shows various FTP Server responses to Client requests:

First Numeric Field

First Numeric Field Meaning
1xx Positive preliminary status – another reply coming.
2xx Positive completion status.
3xx Positive preliminary status – another command must be sent.
4xx Temporary error condition.
5xx Error condition.

Second Numeric Field

Second Numeric Field Meaning
x0x Syntax error in command.
x1x Informational message.
x2x Connection related.
x3x Authentication related.
x4x Unspecified.
x5x File system related.

For example, a Client request to disconnect a FTP connection with the QUIT command will typically be responded with a 221 code from the Server – if the disconnect is successful.

FTP Communication

The FTP Server utilizes the well-known TCP port 21 to field Client requests. FTP Clients may use any available TCP port. The general sequence of FTP events are as follows. As mentioned previous, the only difference with FTP running over IPv6 is the PORT command is replaced with the EPRT command:

FTP Read File Requests:

  1. Client issues TCP connect to Server port 21.
  2. Server sends 220 response to signal success.
  3. Client sends USER message with "username."
  4. Server sends 331 response to signal success.
  5. Client sends PASS message with "password."
  6. Server sends 230 response to signal success.
  7. Client sends TYPE I message for binary transfer.
  8. Server sends 200 response to signal success.
  9. Client sends PORT message with IP address and port.
  10. Server sends 200 response to signal success.
  11. Client sends RETR message with file name to read.
  12. Server creates data socket and connects with client data port specified in the EPRT command.
  13. Server sends 125 response to signal file read has started.
  14. Server sends contents of file through the data connection. This process continues until file is completely transferred.
  15. When finished, Server disconnects data connection.
  16. Server sends 250 response to signal file read is successful.
  17. Clients sends QUIT to terminate FTP connection.
  18. Server sends 221 response to signal disconnect is successful.
  19. Server disconnects FTP connection.

FTP Write Requests:

  1. Client issues TCP connect to Server port 21.
  2. Server sends 220 response to signal success.
  3. Client sends USER message with "username."
  4. Server sends 331 response to signal success.
  5. Client sends PASS message with "password."
  6. Server sends 230 response to signal success.
  7. Client sends TYPE I message for binary transfer.
  8. Server sends 200 response to signal success.
  9. IPv6 applications: Client sends EPRT message with IP address and port. IPv4 applications: Client sends PORT message with IP address and port.
  10. Server sends 200 response to signal success.
  11. Client sends STOR message with file name to write.
  12. Server creates data socket and connects with client data port specified in the previous EPRT or PORT command.
  13. Server sends 125 response to signal file write has started.
  14. Client sends contents of file through the data connection. This process continues until file is completely transferred.
  15. When finished, Client disconnects data connection.
  16. Server sends 250 response to signal file write is successful.
  17. Clients sends QUIT to terminate FTP connection.
  18. Server sends 221 response to signal disconnect is successful.
  19. Server disconnects FTP connection.

FTP Authentication

Whenever a FTP connection takes place, the Client must provide the Server with a username and password. Some FTP sites allow what is called Anonymous FTP, which allows FTP access without a specific username and password. For this type of connection, anonymous should be supplied for username and the password should be a complete e-mail address.

You are responsible for supplying NetX FTP with login and logout authentication routines. These are supplied during the nxd_ftp_server_create and nx_ftp_server_create services and called from the password processing. The difference between the two is the nxd_ftp_server_create input function pointers to login and logout authenticate functions expect the NetX Duo address type NXD_ADDRESS. This data type holds both IPv4 or IPv6 address formats, making this function the duo service supporting both IPv4 and IPv6 networks. The nx_ftp_server_create input function pointers to login and logout authenticate functions expect ULONG IP address type. This function is limited to IPv4 networks. You are encouraged to use the duo service whenever possible.

If the login function returns NX_SUCCESS, the connection is authenticated and FTP operations are allowed. Otherwise, if the login function returns something other than NX_SUCCESS, the connection attempt is rejected.

NetX/NetX Duo FTP Server Module Important Operational Notes and Limitations

NetX/NetX Duo FTP Server Module Operational Notes

FTP Multi-Thread Support

  • The NetX FTP Client services can be called from multiple threads simultaneously. However, read or write requests for a particular FTP Client instance should be done in sequence from the same thread.

RFCs

  • NetX Duo FTP is compliant with RFC 959, RFC 2428 and related RFCs.

NetX/NetX Duo FTP Server Module Limitations

FTP Constraints

The FTP standard has many options regarding the representation of file data. NetX FTP does not implement switch options like ls – al. The NetX FTP Server and the NetX Duo FTP Server expect to receive requests and their arguments in a single packet rather than consecutive packets.

Like UNIX implementations, NetX FTP assumes the following file format constraints:

  • File Type: Binary
  • File Format: Nonprint Only
  • File Structure: File Structure Only

Including the NetX/NetX Duo FTP Server Module in an Application

This section describes how to include either or both the NetX and NetX Duo FTP Server module in an application using the SSP configurator.

Note
It is assumed you are familiar with creating a project, adding threads, adding a stack to a thread and configuring a block within the stack. If you are unfamiliar with any of these items, refer to the first few chapters of the SSP User's Manual to learn how to manage each of these important steps in creating SSP-based applications.

To add the NetX/NetX Duo FTP Server module to an application, simply add it to a thread using the stacks selection sequence given in the following table.

NetX/NetX Duo FTP Server Module Selection Sequence

Resource ISDE Tab Stacks Selection Sequence
g_dns0 NetX FTPServer Threads New Stack> X-Ware> NetX> Protocols> NetX FTPServer
g_dns0 NetX Duo FTPServer Threads New Stack> X-Ware> NetX Duo> Protocols> NetX Duo FTP Server

When the NetX and/or NetX Duo FTP Server module is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.

 

nx_ftp_server_MS.png
NetX/NetX Duo FTP Server Module Stack

In the stack above, the NetX Network Driver (or NetX Duo Network Driver in a NetX Duo stack) has not been populated yet. There are multiple possible selections for the Network Driver; they are not all provided so as not to needlessly complicate the figure and the following configuration tables. The available options depend on the MCU target, but some typical options include:

  • NetX Duo Port using PPP on nxd_ppp
  • NetX Port ETHER on sf_el_nx
  • NetX Port using Cellular Framework on sf_cellular_nsal_nx
  • NetX Port using PPP on nx_ppp
  • NetX Port using Wi-Fi Framework on sf_wifi_nsal_nx

Additionally, in the stack above, the FileX stack has also not been populated yet. There are multiple possible selections for the FileX module; they are not all provided so as not to needlessly complicate the figure and the following configuration tables. The available options depend on the MCU target, but some typical options include:

  • FileX Stub
  • FileX on Block Media (implemented on Block Media Framework on sf_block_media_ram)
  • FileX on USB Mass Storage (implemented on USBX Host Class Mass Storage)

Configuring the NetX/NetX Duo FTP Server Module

The NetX/NetX Duo FTP Server module must be configured by the user for the desired operation. The SSP configuration window automatically identifies (by highlighting the block in red) any required configuration selections, such as interrupts or operating modes, which must be configured for lower-level modules for successful operation. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.

Note
You may want to open your ISDE, create the module and explore the property settings in parallel with looking over the following configuration table values. This helps to orient you and can be a useful hands-on approach to learning the ins and outs of developing with SSP.

Configuration Settings for the NetX/NetX Duo FTP Server Module

ISDE Property Value Description
Internal Thread Priority 16 Internal thread priority selection.
Internal thread time slicing interval (ticks) 2 Internal thread time slicing interval selection.
Maximum clients to serve simultaneously 4 Maximum number of clients allowed.
Control window size (bytes) 400 Control window size selection.
Data window size (bytes) 2048 Data window size selection.
Duration internal services will suspend for (seconds) 1 Duration internal services will suspend for selection.
Maxixum username length (bytes) 20 Maximum username length selection.
Maximum password length (bytes) 20 Maximum password length selection.
Duration allowed with no activity (seconds) 240 Duration allowed with no activity.
Socket retransmit timeout (seconds) 2 Duration for initial timeout.
Maximum queued transmit packets 20 Maximum queued transmit selection.
Number of socket retransmissions 10 Maximum retries per selection.
Binary left shift as multiplier for retry duration 1 Binary left shift as multiplier for retry duration selection.
Name g_ftp_server0 Module name.
Internal thread stack size (bytes) 4096 Internal thread stack size stacks selection.
Name of Login Function ftp_login Name of login function selection.
Name of Logout Function ftp_logout Name of logout function selection.
Name of generated initialization function ftp_server_init0 Name of generated initialization function selection.
Auto Initialization Enable, Disable

Default: Enable
Auto initialization selection.
Note
The example settings and defaults are for a project using the S7G2 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

In some cases, settings other than the defaults for lower-level modules can be desirable. For example, it might be useful to select different MAC Addresses. The configurable properties for the lower-level stack modules are provided in the following sections for completeness and as a reference. 

Note
Most of the property settings for lower-level modules are intuitive and usually can be determined by inspection of the associated properties window from the SSP configurator.

Configuration Settings for the NetX/NetX Duo FTP Server Lower-Level Modules

Only a small number of settings must be modified from the default for the IP layer and lower-level drivers as indicated via the red text in the thread stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and are locked to prevent user modification. The following table identifies all the settings within the properties section for the module:

Configuration Settings for the NetX/NetX Duo IP Instance

ISDE Property Value Description
Name g_ip0 Module name.
IPv4 Address (use commas for separation) 192,168,0,2 IPv4 Address selection.
Subnet Mask (use commas for separation) 255,255,255,0 Subnet Mask selection.
Default Gateway Address (use commas for separation) 0,0,0,0 Default gateway address selection.
**IPv6 Global Address (use commas for separation) 0x2001, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1 IPv6 global address selection.
**IPv6 Link Local Address (use commas for separation, All zeros means use MAC address) 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 IPv6 link local address selection.
IP Helper Thread Stack Size (bytes) 2048 IP Helper Thread Stack Size (bytes) selection.
IP Helper Thread Priority 3 IP Helper Thread Priority selection.
ARP Enable ARP selection.
ARP Cache Size in Bytes 512 ARP Cache Size in Bytes selection.
Reverse ARP Enable, Disable

Default: Disable
Reverse ARP selection.
TCP Enable, Disable

Default: Enable
TCP selection.
UDP Enable, Disable

Default: Enable
UDP selection.
ICMP Enable, Disable

Default: Enable
ICMP selection.
IGMP Enable, Disable

Default: Enable
IGMP selection.
IP fragmentation Enable, Disable

Default: Disable
IP fragmentation selection.
Name of generated initialization function ip_init0 Name of generated initialization function selection.
Auto Initialization Enable, Disable

Default: Enable
Auto initialization function.
Link status change callback NULL Link status change callback selection.
Note
The example settings and defaults are for a project using the Synergy S7G2 MCU Group. Other MCUs may have different default values and available configuration settings.

** Indicates properties that are only available in NetX Duo.

Configuration Settings for the NetX/NetX Duo FTP Common Instance

ISDE Property Value Description
FileX support Enabled, Disabled

Default: Enabled
FileX support selection.
Control Type of Service Normal, Minimum delay, Maximum data, Maximum reliability, Minimum cost

Default: Normal
Control type of service selection.
Data Type of Service Normal, Minimum delay, Maximum data, Maximum reliability, Minimum cost

Default: Normal
Data type of service selection.
Fragmentation option Don't fragment, Fragment okay

Default: Don't fragment
Fragment option selection.
Time to live 128 Time to live selection.
Duration between client inactivity check (seconds) 60 Duration between client inactivity check selection.
Note
The example settings and defaults are for a project using the S7G2 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

Configuration Settings for the NetX/NetX Duo Common Instance

ISDE Property Value Description
Name of generated initialization function nx_common_init0 Name of generated initialization function selection.
Auto Initialization Enable, Disable

Default: Enable
Auto initialization selection.
Note
The example settings and defaults are for a project using the S7G2 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

Configuration Settings for the NetX/NetX Duo Packet Pool Instance

ISDE Property Value Description
Name g_packet_pool0 Module name.
Packet Size in Bytes 640 Packet size selection.
Number of Packets in Pool 16 Number of packets in pool selection.
Name of generated initialization function packet_pool_init0 Name of generated initialization function selection.
Auto Initialization Enable, Disable

Default: Enable
Auto initialization selection.
Note
The example settings and defaults are for a project using the S7G2 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.

NetX/NetX Duo FTP Server Module Clock Configuration

The ETHERC peripheral module uses the PCLKA as its clock source. The PCLKA frequency is set using the SSP configurator Clock tab prior to a build or by using the CGC interface at run-time.

NetX/NetX Duo FTP Server Module Pin Configuration

The ETHERC peripheral module uses pins on the MCU device to communicate to external devices. I/O pins must be selected and configured by the external device as required.  The following table illustrates the method for selecting the pins within the SSP configuration window and the subsequent table illustrates an example selection for the I2C pins.

Note
The selected operation mode determines what peripheral signals available and what MCU pins are required.

Pin Selection for the ETHERC Module

Resource ISDE Tab Pin Selection Sequence
ETHERC Pins Select Peripherals> Connectivity:ETHERC> ETHERC1.RMII
Note
The selection sequence assumes ETHERC1 is the desired hardware target for the driver.

Pin Configuration Settings for the ETHERC1

Property Value Description
Operation Mode Disabled, Custom, RMII

Default: Disabled
Select RMII as the Operation Mode for ETHERC1.
Pin Group Selection Mixed, _A only

Default: _A only
Pin group selection.
REF50CK P701 REF50CK pin.
TXD0 P700 TXD0 pin.
TXD1 P406 TXD1 pin.
TXD_EN P405 TXD_EN pin.
RXD0 P702 RXD0 pin.
RXD1 P703 RXD1 pin.
RX_ER P704 RX_ER pin.
CRS_DV P705 CRS_DV pin.
MDC P403 MDC pin.
MDIO P404 MDIO pin.
Note
The example settings are for a project using the S7G2 Synergy MCU Group and the SK-S7G2 Kit. Other Synergy MCUs and other Synergy Kits may have different available pin configuration settings.

Using the NetX/NetX Duo FTP Server Module in an Application

The steps in using the NetX/NetX Duo FTP Server module in a typical application are:

1. Create the FTP Server using the nx_ftp_server_create (or the nxd_ftp_server_create API for NetX Duo systems).

2. Start the FTP Server using the nx_ftp_server_start API.

3. Create the FTP Client using nx_ftp_client_create API.

4. Connect to the FTP Server using the nx_ftp_client_connect API.

5. Open a file using the nx_ftp_client_open API.

6. Read from a file using the nx_ftp_client_read API.

7. Close a file using the nx_ftp_client_close API.

The following figure illustrates common steps in a typical operational flow diagram:

nx_ftp_server_TA.png
Flow Diagram of a Typical NetX/NetX Duo FTP Server Module Application