Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

Version 1 Next »

Unable to render {include} The included page could not be found.
Unable to render {include} The included page could not be found.

µC/FTPs Example Code

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.

 

 

#define FTPs_PASSIVE_IP_ADDR "192.168.1.2"

#define FTPs_PASSIVE_PORT 2000

static void AppTaskStart (void *p_arg)

{

NET_IP_ADDR addr;

CPU_BOOLEAN success;

NET_ERR net_err;

AppInit_TCPIP(); (1)

AppInit_FS(); (2)

addr = NetASCII_Str_to_IP((CPU_CHAR *) FTPs_PASSIVE_IP_ADDR,

(NET_ERR *)&net_err);

success = FTPs_Init(addr, FTPs_PASSIVE_PORT, DEF_NULL); (3)

if (success == DEF_YES) {

printf("FTP server successfully initialized\n\r");

} else {

printf("FTP server initialization failed\n\r");

}

while (DEF_YES) {

OSTimeDlyHMSM(0, 0, 0, 100);

}

}

    1. Example code in standard mode

 

      1. Initialize the µC/TCP-IP protocol suite.
      2. Initialize the file system.
      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.

#define FTPs_PASSIVE_IP_ADDR "192.168.1.2"

#define FTPs_PASSIVE_PORT 2000

 

extern const CPU_CHAR cert[];

extern const CPU_CHAR key[];

FTPs_SECURE_CFG ftps_secure_cfg;

 

static void AppTaskStart (void *p_arg)

{

NET_IP_ADDR addr;

CPU_BOOLEAN success;

NET_ERR net_err;

AppInit_TCPIP(); (1)

App_FS_Init(); (2)

addr = NetASCII_Str_to_IP((CPU_CHAR *) FTPs_PASSIVE_IP_ADDR,

(NET_ERR *)&net_err);

ftps_secure_cfg.CertPtr = (CPU_CHAR *)&cert[0]; (3)

ftps_secure_cfg.CertLen = Str_Len(cert); (4)

ftps_secure_cfg.Fmt = NET_SOCK_SECURE_CERT_KEY_FMT_PEM; (5)

ftps_secure_cfg.KeyPtr = (CPU_CHAR *)&key[0]; (6)

ftps_secure_cfg.KeyLen = Str_Len(key); (7)

ftps_secure_cfg.CertChain = DEF_NO; (8)

 

success = FTPs_Init(addr, FTPs_PASSIVE_PORT, &ftps_secure_cfg); (9)

if (success == DEF_YES) {

printf("FTP secure server successfully initialized.\n\r");

} else {

printf("FTP secure server initialization failed.\n\r");

}

while (DEF_YES) {

OSTimeDlyHMSM(0, 0, 0, 100);

}

}

    1. Example code in secure mode
      1. Initialize the µC/TCP-IP protocol suite.
      2. Initialize the file system.
      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.
      4. Initialize the length of the public key certificate.
      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
      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.
      7. Initialize the length of the private key certificate.
      8. Initialize the µC/FTPs module with secure mode enabled. The module is then ready to accept secure requests from clients.
      9. Flag to set if the public certificate is chained to another one.
  • No labels