//Delete_Files_timestamp //05/20/2010 @ 20:06 EDT /* Example showing timestamp support in LittleFS */ /* Released into the public domain. */ /* Earle F. Philhower, III */ #ifdef ESP8266 #include #include #elif #defined ESP32 #include #include #endif #include #ifndef STASSID #define STASSID "yourSSID" #define STAPSK "yourPASSWORD" #endif const char *ssid = STASSID; const char *pass = STAPSK; FtpServer ftpSrv; unsigned long int i; char* filelist[30]; long timezone = -5; byte daysavetime = 1; bool getLocalTime(struct tm * info, uint32_t ms) { uint32_t count = ms / 10; time_t now; time(&now); localtime_r(&now, info); if (info->tm_year > (2016 - 1900)) { return true; } while (count--) { delay(10); time(&now); localtime_r(&now, info); if (info->tm_year > (2016 - 1900)) { return true; } } return false; } void listDel(const char * dirname) { Serial.printf("Listing root directory. \n"); Dir root = LittleFS.openDir("/"); root.rewind(); while(root.next()) { File file = root.openFile("r"); String str = root.fileName(); i++; filelist[i] = strdup(str.c_str()); Serial.print(filelist[i]); Serial.print(" "); Serial.print(i); Serial.println(""); time_t cr = file.getCreationTime(); time_t lw = file.getLastWrite(); file.close(); struct tm * tmstruct = localtime(&cr); Serial.printf(" CREATION: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); tmstruct = localtime(&lw); Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); Serial.print("\n"); } if(i >= 8) { for(i = 1;i < 5; i++) //Delete only first four files; keep from getting too many log files. { LittleFS.remove("/" + String(filelist[i])); Serial.print("Removed: "); Serial.print(filelist[i]); Serial.print(" "); Serial.print(i); Serial.println(""); } i = 0; } else { Serial.print("\n"); Serial.println("No Files to remove."); } } void setup() { Serial.begin(115200); // We start by connecting to a WiFi network Serial.println(); Serial.println("\n\n\n\n"); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); Serial.println("Contacting Time Server"); configTime(3600 * timezone, daysavetime * 3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); struct tm tmstruct ; tmstruct.tm_year = 0; getLocalTime(&tmstruct, 5000); delay(2000); Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); Serial.println(""); //Serial.println("Formatting LittleFS filesystem"); //LittleFS.format(); Serial.println("Mount LittleFS"); if (!LittleFS.begin()) { Serial.println("LittleFS mount failed"); return; } ////////////////////////// FTP ///////////////////////////////// //FTP Setup, ensure SPIFFS is started before ftp; //////////////////////////////////////////////////////////////// Serial.println("LittleFS opened!"); Serial.println(""); ftpSrv.begin("esp32", "esp32"); //username, password for ftp. set ports in ESP8266FtpServer.h (default 21, 50009 for PASV) /////////////////////// End FTP////////////////////////////// listDel("/"); } void loop() { ///////////////////////////////////////////////////// FTP /////////////////////////////////// for(int x = 1;x < 5000;x++) { ftpSrv.handleFTP(); } ///////////////////////////////////////////////////////////////////////////////////////////// }