Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Listing 3-1 is shown to demonstrate the µC/FTPs module capabilities in standard mode. That code simply initializes µC/TCP-IP, µC/FS, and µC/FTPs in standard mode.

Listing 3-1 Example code in standard mode

 

L3-1(1) Initialize the µC/TCP-IP protocol suite.

L3-1(2) Initialize the file system.

L3-1(3) Initialize the µC/FTPs module with secure mode disabled. The module is then ready to accept standard requests from clients.

Listing 3-2 is shows the µC/FTPs module capabilities in secure mode. That code simply show how initialize µC/TCP-IP and µC/FS then µC/FTPs in secure mode. A secure FTP server configuration structure, has to be initialized before µC/FTPs can be initialized.

Listing 3-2 Example code in secure mode

L3-2(1) Initialize the µC/TCP-IP protocol suite.

L3-2(2) Initialize the file system.

L3-2(3) Initialize the server public key certificate. The FTPs_SECURE_CFG structure only stores a pointer to the public key meaning that the public key array must be maintained in memory throughout the execution of the FTP server.

L3-2(4) Initialize the length of the public key certificate.

L3-2(5) Format of the key certificates. Supported formats are PEM and DER.
The value can either be:
NET_SOCK_SECURE_CERT_KEU_FMT_PEM or
NET_SOCK_SECURE_CERT_KEU_FMT_DER

L3-2(6) Initialize the server private key certificate. The FTPs_SECURE_CFG structure only stores a pointer to the private key meaning that the public key array must be maintained in memory throughout the execution of the FTP server.

L3-2(7) Initialize the length of the private key certificate.

L3-2(8) Initialize the µC/FTPs module with secure mode enabled. The module is then ready to accept secure requests from clients.

...

  1. This example show how to initialize µC/FTPs:
    1. Start the FTP server's instance.

  2. This example assumes the presence of µC/TCP-IP and µC/FS. It is assume also that all prerequisite modules have been initialized before starting to initialize µC/HTTPs and any web server instance.


Code Block
languagecpp
linenumberstrue
#define  FTPs_PASSIVE_IP_ADDR  "192.168.1.2" 
#define  FTPs_PASSIVE_PORT             2000 
           
CPU_BOOLEAN  FTPs_AppInitServer (void  *p_arg) 
{ 
    NET_IPv4_ADDR  addr;     
    CPU_BOOLEAN    success; 
    NET_ERR        net_err; 
            
 
    addr = NetASCII_Str_to_IPv4((CPU_CHAR *) FTPs_PASSIVE_IP_ADDR,     /* See Note #1.                        */
                                (NET_ERR  *)&net_err); 
    if (net_err != NET_ASCII_ERR_NONE) {
        return (DEF_FAIL);
    }
 
    success = FTPs_Init(addr, FTPs_PASSIVE_PORT, DEF_NULL);            /* See Note #2.	                      */                    
    if (success != DEF_OK) {
        return (DEF_FAIL);
    }
 
    return (DEF_OK);
}


  1. Convert passive string address to IPv4 address (public/internet host address).
  2. Initialize the μC/FTPs module with secure mode disabled. The module is then ready to accept standard requests from clients.