Setting up TFTP client using MQX 4.1

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setting up TFTP client using MQX 4.1

879 Views
andrell24
Contributor I

Hello everyone,

I am working on setting up my embedded program as a TFTP client using MQX 4.1 to download a file from a TFTP server

but have not succeeded yet. Below is my code snippet:

#define ENET_DEVICE             BSP_DEFAULT_ENET_DEVICE

#define ENET_IPADDR             IPADDR(192,168,55,128)

#define MAX_HOSTNAMESIZE        64

void setupTFTPclientAndDownloadFileFromServer()

{

    _ip_address          hostaddr;

    char                 hostname[MAX_HOSTNAMESIZE];

    uint_32              tftp_handle, buffer_size;

    uchar_ptr            buffer_ptr;

    TFTP_DATA_STRUCT     tftp_data;

    boolean              error = FALSE, error2;

    int_32               return_code = 0;

    int_32               i=0,address;

    boolean              next_trans = TRUE;

    _enet_address        enet_address;

   

    error2 = RTCS_create();

    if (error2 != RTCS_OK){

        printf("\nRTCS failed to initialize, error2 = %X", error2);

       

        _task_block();

    }

   

    //Enable IP forwarding

    _IP_forward = TRUE;

    

    ENET_get_mac_address(ENET_DEVICE, ENET_IPADDR, enet_address);

  

    RTCS_resolve_ip_address("192.168.55.134", &hostaddr, hostname, MAX_HOSTNAMESIZE);

    if (!hostaddr) {

         printf("Unable to resolve host.\n");

        

         return;

    }

   

    tftp_data.SERVER = hostaddr;

    tftp_data.FILENAME = "C:\\sampleFile.bin";

    tftp_data.FILEMODE = "octet";

               

                printf("\nDownloading file %s from TFTP server: %s [%ld.%ld.%ld.%ld]\n",

                        tftp_data.FILENAME, hostname, IPBYTES(hostaddr));

               

                tftp_handle = (*FT_TFTP->OPEN)((pointer) &tftp_data);

                if (tftp_handle != RTCS_OK) { 

                    printf("\nError opening file %s\n", tftp_data.FILENAME);            //******THIS IS WHERE THE COMPILER ENDS UP

                }

                else {

                    printf("\Success opening file %s\n", tftp_data.FILENAME);

                   

                    while (!(*FT_TFTP->EOFT)()) {

                        next_trans = TRUE;

                        while(1) {

                            //Read TFTP

                            buffer_ptr = (*FT_TFTP->READ)( &buffer_size );

                           

                            if((NULL == buffer_ptr)||(TFTP_DATA_SIZE != buffer_size)) {

                                next_trans = FALSE;

                            }

                           

                            switch (buffer_size) {

                                case (RTCSERR_TFTP_TIMEOUT):

                                    printf("\nTFTP timeout\n");

                                    error = TRUE;

                                    break;

                                case (RTCSERR_TFTP_ERROR + 1):

                                    printf("\nFile %s not found\n", tftp_data.FILENAME);

                                    error = TRUE;

                                    break;

                                case (RTCSERR_TFTP_ERROR + 2):

                                    printf("\nAccess violation\n");

                                    error = TRUE;

                                    break;

                                case (RTCSERR_TFTP_ERROR + 3):

                                    printf("\nDisk full or allocation exceeded\n");

                                    error = TRUE;

                                    break;

                                case (RTCSERR_TFTP_ERROR + 4):

                                    printf("\nIllegal TFTP operation\n");

                                    error = TRUE;

                                    break;

                                case (RTCSERR_TFTP_ERROR + 5):

                                    printf("\nUnknown transfer ID\n");

                                    error = TRUE;

                                    break;

                                case (RTCSERR_TFTP_ERROR + 6):

                                    printf("\nFile already exists\n");

                                    error = TRUE;

                                    break;

                                case (RTCSERR_TFTP_ERROR + 7):

                                    printf("\nNo such user\n");

                                    error = TRUE;

                                    break;

                                default:

                                    break;

                            } //Endswitch

                           

                            //Transaction finished

                            if((NULL == buffer_ptr)||(TFTP_DATA_SIZE != buffer_size)) {

                                return_code = (*FT_TFTP->CLOSE)();

                                fclose(flash_hdl);

                            }

                        } //End Read TFTP

                        break;

                    }

                    return_code = (*FT_TFTP->CLOSE)();

                }

}

I am not being able to get an RTCS_OK return value after calling this method (*FT_TFTP->OPEN)((pointer) &tftp_data) so it does not go to

the downloading process.


Please have a look at my code and advice what should be corrected. Thank you very much.

Best Regards,

Darrell

0 Kudos
Reply
1 Reply

590 Views
RadekS
NXP Employee
NXP Employee

Hi Darrell,

currently I do not see anything really wrong in your code. But I am just not sure with source file name tftp_data.FILENAME = "C:\\sampleFile.bin"; Shouldn't be there just one back slash? "C:\sampleFile.bin".

Of course, it depends on your ftp server, but it rather looks like typo from my point of view.

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply