nopnop2002 / esp-idf-ftpServer

ftp server for esp-idf using FAT file system
MIT License
35 stars 12 forks source link

How to list files in lowercase? #9

Closed LFRS closed 2 years ago

LFRS commented 2 years ago

Hi,

Is it possible to list files in lowercase or allow files to be lowercase and uppercase?

Best Regards, Luís

nopnop2002 commented 2 years ago

No.

fopen function provided by esp-idf always creates a file in uppercase.

These will be treated the same.

fopen ("/spiflash/hello.txt", "wb"); fopen ("/spiflash/HELLO.TXT", "wb");

LFRS commented 2 years ago

Hi @nopnop2002,

I've changed the "FTP_ftp_list_dir" function to be able to list file and folder names in lowercase. Added the function "FTP_tolower(de->d_name);"

static void FTP_tolower (char str) { while (str && str != '\0') { str = (char)tolower((int)(str)); str++; } }

static ftp_result_t FTP_ftp_list_dir(char list, uint32_t maxlistsize, uint32_t listsize) { uint next = 0; uint listcount = 0; ftp_result_t result = E_ftp_RESULT_CONTINUE; struct dirent *de;

// read up to 8 directory items
while (((maxlistsize - next) > 64) && (listcount < 8)) 
{
    de = readdir(ftp_data.dp);                                                          // Read a directory item
    if (de == NULL) 
    {
        result = E_ftp_RESULT_OK;
        break;                                                                          // Break on error or end of dp
    }
    if (de->d_name[0] == '.' && de->d_name[1] == 0) continue;                           // Ignore . entry
    if (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == 0) continue;   // Ignore .. entry

    // add the entry to the list
    FTP_tolower(de->d_name);
    ESP_LOGI(FTP_TAG, "Add to dir list: %s", de->d_name);
    next += FTP_ftp_get_eplf_item((list + next), (maxlistsize - next), de);
    listcount++;
}
if (result == E_ftp_RESULT_OK) 
{
    FTP_ftp_close_files_dir();
}
*listsize = next;
return result;

}

Thanks, Luis