Versions Compared

Key

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

Establishes a connection to a FTP server.

Files

ftp-c.h/ftp-c.c

Prototype

Code Block
          CPU_BOOLEAN  FTPc_Open (       FTPc_CONN        *p_conn,
                                  const  FTPc_CFG         *p_cfg,
                                  const  FTPc_SECURE_CFG  *p_secure_cfg,                                    
								         CPU_CHAR         *p_host_server, 
                                         CPU_INT16U        port_nbr, 
                                         CPU_CHAR         *p_user, 
                                         CPU_CHAR         *p_pass,
                                         FTPc_ERR         *p_err);

Arguments

p_conn

Pointer to FTPc Connection object.

p_cfg

Pointer to FTPc Configuration object.

server_ip Server IP address.

...

p_secuce_cfg

Pointer to FTPc Secure Configuration object.
DEF_NULL, if secured connection is not required

p_host_server

Pointer to hostname or IP address string of the server.

port_nbr 

Server TCP port number.

p_user 

Username of the FTP server.

p_pass 

Password for specified FTP user.

p_

...

Pointer to a secure configuration structure

If secured connection is required.

DEF_NULL

If secured connection is note required.

 

...

err 

Pointer to variable that will receive the return error code from this function.

TFTPc_ERR_NONE
FTPc_ERR_CONN_FAIL
FTPc_ERR_TX_CMD
FTPc_ERR_RX_CMD_RESP_FAIL
FTPc_ERR_LOGGEDIN       

Returned Values

DEF_OK,     FTP connection successfully established;
DEF_FAIL, otherwise.

Required Configuration

  • The network security manager MUST be available and enabled to open a secure FTP connection (i.e: in “net_cfg.h”, NET_SECURE_CFG_EN should be DEF_ENABLED AND NET_TCP_CFG_

...

  • EN should be

...

  • DEF_ENABLED). See µC/TCPIP user manual for more information about the network security manager.
  • A network security module MUST be included in the project (i.e: Mocana’s NanoSSL) to use the network security manager functionalities.

Notes / Warnings

  • None.

Example Usage

Code Block
          #define  FTP_SERVER_IP_ADDR       "192.168.1.101"
          #define  FTP_SERVER_PORT                      21
           
          #define  FTPc_USER                    "anonymous"
          #define  FTPc_PW               "test@micrium.com"
           
          FTPc_CONN    conn; 
          CPU_INT16U   server_port;
          CPU_BOOLEAN  result;
          FTPc_ERR     err;
           
          server_port = FTP_SERVER_PORT;
           
          result = FTPc_Open(&conn, DEF_NULL, DEF_NULL, FTP_SERVER_IP_ADDR, server_port, FTPc_USER, FTPc_PW, &err);
          if (result != DEF_OK) {
              printf("FTPc_Open() failed.\n\r");
          }


Code Block

          #define  FTP_SERVER_IP_ADDR       "192.168.1.101"
          #define  FTP_SERVER_PORT_SECURE               990
          #define  FTP_COMMON_NAME              "micrium.com"
           
          #define  FTPc_USER                    "anonymous"
          #define  FTPc_PW               "test@micrium.com"
           
          FTPc_CONN        conn;
          CPU_INT16U       server_port;
          CPU_BOOLEAN      result;
          FTPc_SECURE_CFG  ftpc_secure_cfg;
          FTPc_ERR         err;
           
          
          server_port = FTP_SERVER_PORT_SECURE; 
           
          Str_Copy(ftpc_secure_cfg.CommonName, FTP_COMMON_NAME);
          ftpc_secure_cfg.TrustCallback = (NET_SOCK_SECURE_TRUST_FNCT)NetSecure_TrustInvalidSig;
           
          result = FTPc_Open(&conn,
                              DEF_NULL,
                             &ftpc_secure_cfg,
                              FTP_SERVER_IP_ADDR
                              server_port,                            
                              FTPc_USER,                             
                              FTPc_PW,                                                     
                             &err);
          if (result != DEF_OK) { 
              printf("Secure FTPc_Open() failed.\n\r");  
          }