开发者

FTP List format

开发者 https://www.devze.com 2022-12-23 09:16 出处:网络
I\'m writing an embedded ftp server, and I cannot get the 开发者_如何学编程listing format correctly. The server works completely, only programs like FileZilla cannot interpret the listing format. Here

I'm writing an embedded ftp server, and I cannot get the 开发者_如何学编程listing format correctly. The server works completely, only programs like FileZilla cannot interpret the listing format. Here's a sample listing:

-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

Which is basically:

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

What am I doing wrong?

Thanks, Yvan


As others have already mentioned, you need to use spaces instead of tabs. Here's a sprintf from another embedded FTP server that should work:

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

permstr is set to a string like "-rw-rw-rw-".

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

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);


Since you did not specify the programming language, I thought I would give my 2cents to this....

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

I have decided to include the C# regexp's below to show, this can be adapted to suit your needs,

            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);

Notice the fact, there is no tab, it is purely spaces...and be careful, some FTP clients can read the listing as either MSDOS or Unix...


The typical ftp server would shell out to ls -l for the directory listing. I believe this output contains space characters which align the output, not tab characters.

The only way you can be certain as to why FileZilla is not parsing your directory listing is to get the open source for FileZilla and watch what is happening in the debugger. But I think you can make progress simply by duplicating the output of ls as exactly as possible, including whitespace.

0

精彩评论

暂无评论...
验证码 换一张
取 消