From a328f5ae9743eab7049e5fe78768495527a8995c Mon Sep 17 00:00:00 2001 From: Lago Date: Fri, 3 Apr 2026 20:27:20 +0200 Subject: [PATCH] fix: FTP storage type (SD_MMC not FFAT), SD used-space walk - Define FTP_SERVER_NETWORK_TYPE=6 and STORAGE_TYPE=10 directly to bypass FtpServerKey.h platform detection that was overriding storage to FFAT - Fix calcDirSize: properly close files, use name() for recursive path - Add SD debug logging for used-space calculation - This fixes file transfers (read/write) failing via FTP --- platformio.ini | 6 ++++-- src/main.cpp | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/platformio.ini b/platformio.ini index dd938c1..7ce5e8a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -36,11 +36,13 @@ build_flags = -Wl,--wrap=esp_ota_mark_app_valid_cancel_rollback ; Enable LVGL simple include -DLV_CONF_INCLUDE_SIMPLE - ; FTP server: must define BOTH network + storage with numeric values - ; to prevent FtpServerKey.h from defaulting to FFAT + ; FTP server: define STORAGE_TYPE and FTP_SERVER_NETWORK_TYPE directly + ; to bypass FtpServerKey.h platform detection entirely ; NETWORK_ESP32=6, STORAGE_SD_MMC=10 -DDEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32=6 -DDEFAULT_STORAGE_TYPE_ESP32=10 + -DFTP_SERVER_NETWORK_TYPE=6 + -DSTORAGE_TYPE=10 ; Suppress deprecation warnings -Wno-deprecated-declarations ; Allow #warning without failing build diff --git a/src/main.cpp b/src/main.cpp index ae8e848..e47bc31 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -105,15 +105,18 @@ static uint64_t calcDirSize(fs::FS &fs, const char *dirname) { uint64_t total = 0; File root = fs.open(dirname); if (!root || !root.isDirectory()) return 0; - File f = root.openNextFile(); - while (f) { + File f; + while ((f = root.openNextFile())) { if (f.isDirectory()) { - total += calcDirSize(fs, f.path()); + String path = f.name(); + f.close(); + total += calcDirSize(fs, path.c_str()); } else { total += f.size(); + f.close(); } - f = root.openNextFile(); } + root.close(); return total; } @@ -121,9 +124,12 @@ static void updateSdInfo() { if (!sd_ok) return; uint64_t total = SD_MMC.totalBytes() / (1024ULL * 1024ULL); uint64_t used = SD_MMC.usedBytes() / (1024ULL * 1024ULL); + Serial.printf("[SD] API: used=%llu MB, total=%llu MB\n", used, total); /* SD_MMC.usedBytes() returns 0 on exFAT / large cards — walk filesystem */ if (used == 0 && total > 0) { - used = calcDirSize(SD_MMC, "/") / (1024ULL * 1024ULL); + uint64_t walked = calcDirSize(SD_MMC, "/"); + used = walked / (1024ULL * 1024ULL); + Serial.printf("[SD] Walk: %llu bytes = %llu MB\n", walked, used); } ui_set_sd(used, total); }