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