To use the FTP library:
  1. Enable the wireless LAN with SysSetWLANPower function and initialize the wireless LAN with SysWLANInit function.
    Sample
        SysSetWLANPower(SYS_WLAN_POWER_AUTO);
        SysWLANInit(NULL);
    

  2. Call SysGetWLANConnectStatus function and wait until the wireless LAN is connected. In the meantime, you need to keep calling the Idle function.
    Sample
        unsigned int waitStartTick;
    
        ...
    
        waitStartTick = GetTickCount();
        do{
            SysGetWLANConnectStatus(&status);
            if (status == SYS_WLAN_STATUS_CONNECTED)
                break;
            Idle();
        }while (GetTickCount() - waitStartTick < WLAN_CONNECTION_TIMEOUT);
        if (status != SYS_WLAN_STATUS_CONNECTED){
            // WLAN timeout error
            ...
    
        }
    

  3. Call the FTP_Connect function to connect to the FTP server.
    Sample
        int ret;
    
        ...
    
        ret = FTP_Connect((char *)ftpHost, 21, FTP_PASV, ResponseCb);
        if (ret != M2M_SUCCESS){
            // Error
            ...
        }
    

  4. Log in to the FTP server by sending the username and password with the FTP_Command function.
    Sample
        ret = FTP_Command(FTP_CMD_USERNAME, (char *)ftpUsername, NULL);
        if (ret != M2M_SUCCESS){
            // Error
            ...
        }
        ret = FTP_Command(FTP_CMD_PASSWORD, (char *)ftpPassword, NULL);
        if (ret != M2M_SUCCESS){
            // Error
            ...
        }
    

  5. Specify the current working directory and data type with the FTP_Command function.
    Sample
        ret = FTP_Command(FTP_CMD_CHPATH, (char *)ftpPath, NULL);
        if (ret != M2M_SUCCESS){
            // Error
            ...
        }
        ret = FTP_Command(FTP_CMD_TYPESET, "A", NULL);
        if (ret != M2M_SUCCESS){
            // Error
            ...
        }
    

  6. Generate the send file names with the FTP_CreateRemoteFilename function. (Optional)
    Send the file with the FTP_Command function.
    Sample
        /* Create file names */
        memset(remoteName, 0, sizeof(remoteName));    // remoteName: Target file name
        memset(tempName, 0, sizeof(tempName));        // tempName:   Temporary file name
        ret = FTP_CreateRemoteFilename(FTP_NAME_TIME_NOID, uploadFile, remoteName, tempName);
        if (ret != M2M_SUCCESS){
            // Error
            ...
        }
        ...
        /* Upload a file with the temporary file name */
        ret = FTP_Command(FTP_CMD_PUT, (char *)uploadFile, tempName);
        if (ret != M2M_SUCCESS){
            // Error
            ...
        }
        ...
        /* Rename the file to the target file name */
        ret = FTP_Command(FTP_CMD_RENAME, tempName, remoteName);
        if (ret != M2M_SUCCESS){
            // Error
            ...
        }
    

  7. Receive a file with the FTP_Command function
    Sample
        ret = FTP_Command(FTP_CMD_GET, (char *)downloadFile, remoteName);
        if (ret != M2M_SUCCESS){
            // Error
            ...
        }
    
    

  8. Log out of the FTP server with the FTP_Command function.
    Quit the FTP client with the FTP_Finish function.
    Sample
        FTP_Command(FTP_CMD_QUIT, NULL, NULL);
        FTP_Finish();
    
    

  9. Disable the wireless LAN with SysSetWLANPower function.
    Sample
        SysSetWLANPower(SYS_WLAN_POWER_OFF);
    

See also



Last updated: 2022/04/08