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
This commit is contained in:
Lago
2026-04-03 20:27:20 +02:00
parent b31e80a71b
commit a328f5ae97
2 changed files with 15 additions and 7 deletions
+4 -2
View File
@@ -36,11 +36,13 @@ build_flags =
-Wl,--wrap=esp_ota_mark_app_valid_cancel_rollback -Wl,--wrap=esp_ota_mark_app_valid_cancel_rollback
; Enable LVGL simple include ; Enable LVGL simple include
-DLV_CONF_INCLUDE_SIMPLE -DLV_CONF_INCLUDE_SIMPLE
; FTP server: must define BOTH network + storage with numeric values ; FTP server: define STORAGE_TYPE and FTP_SERVER_NETWORK_TYPE directly
; to prevent FtpServerKey.h from defaulting to FFAT ; to bypass FtpServerKey.h platform detection entirely
; NETWORK_ESP32=6, STORAGE_SD_MMC=10 ; NETWORK_ESP32=6, STORAGE_SD_MMC=10
-DDEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32=6 -DDEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32=6
-DDEFAULT_STORAGE_TYPE_ESP32=10 -DDEFAULT_STORAGE_TYPE_ESP32=10
-DFTP_SERVER_NETWORK_TYPE=6
-DSTORAGE_TYPE=10
; Suppress deprecation warnings ; Suppress deprecation warnings
-Wno-deprecated-declarations -Wno-deprecated-declarations
; Allow #warning without failing build ; Allow #warning without failing build
+11 -5
View File
@@ -105,15 +105,18 @@ static uint64_t calcDirSize(fs::FS &fs, const char *dirname) {
uint64_t total = 0; uint64_t total = 0;
File root = fs.open(dirname); File root = fs.open(dirname);
if (!root || !root.isDirectory()) return 0; if (!root || !root.isDirectory()) return 0;
File f = root.openNextFile(); File f;
while (f) { while ((f = root.openNextFile())) {
if (f.isDirectory()) { if (f.isDirectory()) {
total += calcDirSize(fs, f.path()); String path = f.name();
f.close();
total += calcDirSize(fs, path.c_str());
} else { } else {
total += f.size(); total += f.size();
f.close();
} }
f = root.openNextFile();
} }
root.close();
return total; return total;
} }
@@ -121,9 +124,12 @@ static void updateSdInfo() {
if (!sd_ok) return; if (!sd_ok) return;
uint64_t total = SD_MMC.totalBytes() / (1024ULL * 1024ULL); uint64_t total = SD_MMC.totalBytes() / (1024ULL * 1024ULL);
uint64_t used = SD_MMC.usedBytes() / (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 */ /* SD_MMC.usedBytes() returns 0 on exFAT / large cards — walk filesystem */
if (used == 0 && total > 0) { 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); ui_set_sd(used, total);
} }