FTP question

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

FTP question

1,204 Views
troide
Contributor II

Hello Community,

 

In my project I run a ftp server on a sdcard file system. I use TWR-K60f120 and MQX 4.1. Mostly, I used code in web_hvac demo to run the FTP and Telnet server (attached rtcs.c)

 

I use a few different ftp clients such as Filezilla, Internet explorer and Windows explorer . Once I connect I could see the list of the files on the sd card. The problem is that I can not open them or transfer them to my local PC.

this image shows the error message once I try to open a text file.

 

15954_15954.pngfig2.png

 

In the task debugger I get the following error (unknown error 0x3057)

 

15955_15955.pngfig1.png

All rtcs setting are in default values.

I used to work with MQX 4.0 and I never had these issues! Any suggestion? idea?

 

Cheers!

Sam

Original Attachment has been moved to: rtcs.c.zip

Tags (3)
0 Kudos
5 Replies

728 Views
troide
Contributor II

I wireshark the ftp transaction and as you can see in the snapshot below every time clinet request CWD, the server adds a fake subdirectorty with the same name to the original directory address. That's why it can not find the files.

wireshark.png

is there anyway to handle this problem?

0 Kudos

728 Views
troide
Contributor II

As I mentioned in the last post there is a bug with CWD command. I modified ftpsrv_cwd(FTPSRV_SESSION_STRUCT* session) in ftpsrv_cmd.c

int32_t ftpsrv_cwd(FTPSRV_SESSION_STRUCT* session)

{

    int       error;

    char*     path;

    char*     new_path;

    uint32_t  path_size;

    void*     dir_ptr;

    char*     full_path;

    uint32_t  wrong_path;

    if (session->cmd_arg == NULL)

    {

        session->message = (char*) ftpsrvmsg_badsyntax;

        return(FTPSRV_ERROR);

    }

    ftpsrv_convert_percents(session->cmd_arg);

    path = ftpsrv_strip_path_delimiters(session->cmd_arg);

    path_size = strlen(path)+1;

       

    /* Get absolute directory path in filesystem */

    full_path = ftpsrv_get_full_path(session, path, &wrong_path);

    if (full_path == NULL)

    {

        if (wrong_path)

        {

            session->message = (char*) ftpsrvmsg_cd_error;

        }

        else

        {

            session->message = (char*) ftpsrvmsg_no_memory;

        }

        return(FTPSRV_ERROR);

    }

    /* Try to open directory only for reading so we know if directory exists */

    dir_ptr = _io_mfs_dir_open(session->fs_ptr, full_path, "*r");

    if (dir_ptr == NULL)

    {

        session->message = (char*) ftpsrvmsg_cd_error;

        _mem_free(full_path);

        return(FTPSRV_ERROR);

    }

    _io_mfs_dir_close(dir_ptr);

    /* Get path relative to FTP root so we can set it as new current directory */

    new_path = ftpsrv_get_relative_path(session, full_path);

    _mem_free(full_path);

    if (!new_path)

    {

        session->message = (char*) ftpsrvmsg_no_memory;

        return(FTPSRV_ERROR); 

    }

    /* If everything went right, set path we chdir'd to as session current path */

    if (session->cur_dir)

    {

        _mem_free(session->cur_dir);

    }

    /*FIXME (SM)*/

    new_path[0]='\\';

    new_path[1]='\0';

    session->cur_dir = new_path;

    return (ftpsrv_pwd(session));

}

now it works for root directory.

Cheers,

Sam

728 Views
Rick_Li
NXP Employee
NXP Employee

I appreciate your patience on this issue!

Please refer to the demo of FTP demo which is available at:

c:\Freescale\Freescale_MQX_4_1\rtcs\examples\shell\

the demo uses ramdisk at a: as the root directory.

You can open an MFS device on SD card driver according to mfs sdcard demo. "ftpd start" command on shell starts the FTP server in the demo.

the MFS-SD demo is located at:

C:\Freescale\Freescale_MQX_4_1\mfs\examples\sdcard

0 Kudos

728 Views
troide
Contributor II

Yong,

I tried "ftpsrv start" and "tftpd start". None of them worked well. I used filezilla as the clinet tool!

Sam

0 Kudos

728 Views
adyr
Contributor V

Hi,

I'm not sure if this is the same problem I have just had. It appears some FTP tools pass / in the file paths but the MFS file systems can't cope, especially when it ends up with something like "a:\/newFile".

I have added a loop to replace all / with \ and that seems to fix the problem for me:

int32_t ftpsrv_cwd(FTPSRV_SESSION_STRUCT* session)
{
    char*     path;
    char*     new_path;
    char*     full_path;
    int32_t   error;
    uint32_t  wrong_path;

    if (session->cmd_arg == NULL)
    {
        session->message = (char*) ftpsrvmsg_badsyntax;
        return(FTPSRV_ERROR);
    }

    rtcs_url_decode(session->cmd_arg);
    path = rtcs_path_strip_delimiters(session->cmd_arg);
    char *tmp = path;

    /* Correct path slashes */
    while (*tmp != '\0')
    {
        if (*tmp == '/')
        {
            *tmp = '\\';
        }
        tmp++;
    }

    /* Get absolute directory path in filesystem */
    full_path = ftpsrv_get_full_path(session, path, &wrong_path);
    if (full_path == NULL)

If this is a genuine fix and I have not missed another configuration option somewhere then maybe Freescale can update the library to include it I someway.

Best regards,
Adrian.

0 Kudos