FTP List Format

I am writing an embedded ftp server and I cannot get the list format correctly. The server runs fully, only programs such as FileZilla cannot interpret the list format. Here is an example:

-rwxr--r--  1   owner   group 640   1970 01 01  test
-rwxr--r--  1   owner   group 13440 1970 01 01  test.html
-rwxr--r--  1   owner   group 512   1970 01 01  test2.txt

Mainly:

permissions[tab]number?[tab]owner[tab]group[tab]filesize[tab]date[tab]filename 

What am I doing wrong?

Thanks Ivan

+5
source share
3 answers

As already mentioned, you need to use spaces instead of tabs. Here's sprintf from another built-in FTP server that should work:

sprintf(line, "%s   1 %-10s %-10s %10lu Jan  1  1980 %s\r\n",
    permstr, username, username,
    length,
    filename);

permstrset to type string "-rw-rw-rw-".

As for date formats, these two should work, with the top part being used if the date is more than 6 months:

if (dfmt)
    sprintf(buf, "%3.3s %2d  %04d", month_name, month_num, year);
else
    sprintf(buf, "%3.3s %2d %02d:%02d", month_name, month_num, hour, minute);
+7
source

, , 2 ....

permissions[tab]number?[tab]owner[tab]group[tab]filesize[tab]date[tab]filename 
                ^^^^^^^                                      ^^^^
             no of inodes                      Dates can vary, it can be year on its own or Month, Day

# regexp , , ,

            private Regex ftpUnixListInfo = new Regex(
                @"(?" +
                @"(?[-|d|r|w|x]+)\s+" +
                @"(?\d+)\s*" +
                @"(?\w+)?\s+" +
                @"(?\w+)\s*" +
                @"(?\d+)\s+" +
                @"(?\w+)\s+" +
                @"(?\d{1,2})\s+" +
                @"(?:(?\d{2}\:\d{2})|(?\d{4}))\s+" +
                @"(?.+))",
                RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace
                | RegexOptions.Compiled);

            // Regex for Microsoft FTP Server
            private Regex ftpMsListInfo = new Regex(
                @"(?" +
                @"(?\d+-\d+-\d+)\s+" +
                @"(?\d+\:\d+(AM|PM))\s*" +
                @"(?((?\)|(?\d+))\s*)" +
                @"(?\w+))",
                RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace
                | RegexOptions.Compiled);

, , ... , FTP- MSDOS Unix...

+7

ftp- ls -l . , , , .

The only way to find out why FileZilla is not parsing your directory listing is to open the source code for FileZilla and see what happens in the debugger. But I think that you can make progress simply by duplicating the output lsas accurately as possible, including spaces.

+1
source

All Articles