Versions Compared

Key

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

Table of Contents

Working Project with µC/TCP-IP

The first step before including µC/FTPc is to have a working project with µC/TCP-IP. As previously mentioned, Micriµm may offer an example with the µC/OS-III kernel, µC/TCP-IP and even µC/FTPc for many evalboards. 

If no project with µC/TCP-IP is available for your platform, you should follow the µC/TCP-IP Getting Started Guide to ensure you have a working project before installing µC/FTPc. Then you can follow the steps to build and run your first µC/FTPc sample application shown below.

Including µC/FTPc Stack Source Code

Configuring Compiler settings

Add the following include paths to your project’s C compiler settings:

\Micrium\Software\uC-FTPc

Copying and Modifying Template Files

Copy the file from the µC/FTPc configuration folder into your application as illustrated below.

Panel
titleFigure - FTPc Template File Copy

Image Added


Adding µC/FTPc Example Application Code

The file app.c contains the application code, and was written to illustrate the capabilities of the µC/FTPc module. That code simply initializes the RTOS, µC/TCP-IP, and µC/FS, and creates a few tasks and other kernel objects that will give the user information about the state of the system.

Note that some sections of the source code have been removed or modified to help focus on the µC/FTPc module use.

The example bellow demonstrates the µC/FTPc module capabilities in both standard and secure mode. The client connects to a remote FTP server in standard mode, perform file download and upload operations before closing the connection.

Code Block
languagecpp
firstline1
titleListing - FTPc Example Application Code
linenumberstrue
#define  FTP_SERVER_IP_ADDR       "192.168.1.101" 
#define  FTP_SERVER_PORT                      21 
#define  FTP_SERVER_PORT_SECURE              990 
           
#define  FTPc_USERNAME                "anonymous" 
#define  FTPc_PASSWORD           "test123micrium"  
           
#define  FTPs_COMMON_NAME          "micrium.com"
           
#define  RX_FILE_REMOTE           "file_remote_1" 
#define  RX_FILE_LOCAL             "\\file_local" 
#define  TX_FILE_REMOTE              "file_local" 
#define  TX_FILE_LOCAL          "\\file_remote_2"

#define  FTPc_BUF_LEN_MAX                   4096

#if  (NET_SECURE_CFG_EN == DEF_ENABLED) 
static  FTPc_SECURE_CFG   ftpc_secure_cfg;
#endif

static  void  AppTaskStart (void  *p_arg)                           	/* See Note #1. */
{ 
    FTPc_CONN    conn;
    CPU_BOOLEAN  result; 
    FTPc_ERR     err_ftpc;
#if (FTPc_CFG_USE_FS != DEF_ENABLED)
    CPU_INT08U         buf[FTPc_BUF_LEN_MAX];
    CPU_INT32U         file_size;
#endif

    result = FTPc_Open(&conn,											/* See Note #2. */
                        DEF_NULL,                                        
                        DEF_NULL, 
                        FTP_SERVER_IP_ADDR,
                        FTP_SERVER_PORT,                                
                        FTPc_USERNAME,                                
                        FTPc_PASSWORD,                                 
                       &err_ftpc);
	if (result != DEF_OK) { 
        printf("FTPc_Open() failed.\n\r"); 
        return; 
    } 
           
#if (FTPc_CFG_USE_FS == DEF_ENABLED)          
    result = FTPc_RecvFile(&conn,										/* See Note #3. */
                            RX_FILE_REMOTE,                                           
                            RX_FILE_LOCAL, 
                           &err_ftpc); 
    if (result != DEF_OK) { 
        printf("FTPc_RecvFile() failed.\n\r"); 
        FTPc_Close(&conn, &err_ftpc); 
        return; 
    } 
         
    result = FTPc_SendFile(&conn,										/* See Note #4. */
                            TX_FILE_REMOTE,                                           
                            TX_FILE_LOCAL, 
                            DEF_FALSE, 
                           &err_ftpc); 
    if (result != DEF_OK) { 
        printf("FTPc_SendFile() failed.\n\r"); 
        FTPc_Close(&conn, &err_ftpc); 
        return; 
    } 
#else

	result = FTPc_RecvBuf(&conn, 										/* See Note #3. */
                           RX_FILE_REMOTE, 
                          &buf[0], 
                           FTPc_BUF_LEN_MAX, 
                          &file_size, 
                          &err_ftpc);
    if (result != DEF_OK) { 
        printf("FTPc_RecvBuf() failed.\n\r"); 
        FTPc_Close(&conn, &err_ftpc); 
        return; 
    } 
    
    result = FTPc_SendBuf(&conn, 										/* See Note #4. */
                           TX_FILE_REMOTE, 
                          &buf[0], 
                           file_size, 
                           DEF_NO, 
                          &err_ftpc);
    if (result != DEF_OK) { 
        printf("FTPc_SendBuf() failed.\n\r"); 
        FTPc_Close(&conn, &err_ftpc); 
        return; 
    } 
#endif

    result = FTPc_Close(&conn, &err_ftpc);                        		/* See Note #5. */
    if (result != DEF_OK) { 
        printf("FTPc_Close() failed.\n\r"); 
        return; 
    }
}


Panel
bgColor#f0f0f0
  1. µC/FTPc executes into the caller’s task context. All interface functions are blocking calls, until completion or error. µC/FTPc does not rely directly on any Real-Time Operating System (RTOS), but does rely on µC/TCP-IP.
  2. Establish a connection with the FTP server with the secure mode disabled.
  3. Transmit a file from the FTP server to the target running µC/FTPc.
  4. Transmit a file from the target running µC/FTPc to the FTP server.
  5. Close connection with server.
  6. Initialize the common name of the FTP server.
  7. Initialize the trust secure callback function.
  8. Establish a secure connection with the FTP server.
  9. Transmit a file from the secure FTP server to the target running µC/FTPc.
  10. Transmit a file from the target running µC/FTPc to the secure FTP server.
  11. Close the secure connection with the server.
  12. Example of trust secure callback function.
  13. Depending on the un-trusted reason, return DEF_YES to trust the server certificate or return DEF_NO to distrust the server certificate.