From a3752b3f8cd04e4f80f969b07dd50db0bd8e38e0 Mon Sep 17 00:00:00 2001 From: anschrammh Date: Tue, 28 Jan 2020 12:33:01 +0100 Subject: [PATCH] Now retrieving the file's last modification date and sending it to the FTP client, I still need to figure out how to set the last modification date when a file is modified by the client though --- src/app/FTPServer.h | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/app/FTPServer.h b/src/app/FTPServer.h index f4fcf8b..770ef41 100644 --- a/src/app/FTPServer.h +++ b/src/app/FTPServer.h @@ -824,18 +824,33 @@ class FTPServer : public TCPServer if (currentDirectory) { currentDirectory.rewindDirectory(); - while (true) //Maybe be remove in the future to improve responsiveness + while (true) //May be removed in the future to improve responsiveness { File fileOrDir = currentDirectory.openNextFile(); if (!fileOrDir) //No more files in the directory break; - #ifdef DEBUG_FTPS - Serial.printf("Filename : %s\n", fileOrDir.name()); - #endif + //We try to retrieve the last modification date + const time_t fileModifDate = fileOrDir.getLastWrite(); + struct tm *timeP = localtime(&fileModifDate); + //Buffer necessary to store the month's three letter abbreviation + char month[4] = ""; - client->_dataClient.printf("%crwxrwxrwx 1 owner esp8266 %d Aug 26 16:31 %s\r\n", fileOrDir.isDirectory() ? 'd' : '-', fileOrDir.isDirectory() ? 0 : fileOrDir.size(), fileOrDir.name()); + #ifdef DEBUG_FTPS + Serial.printf("Filename : %s, %s %d %d %d:%d\n", fileOrDir.name(), monthNumTo3LetterAbbreviation(month, timeP->tm_mon), timeP->tm_mon, timeP->tm_mday, timeP->tm_hour, timeP->tm_min); + #endif + + char zero_prepended[3][3] = {"","",""}; + + client->_dataClient.printf("%crwxrwxrwx 1 owner esp8266 %d %s %s %s:%s %s\r\n", + fileOrDir.isDirectory() ? 'd' : '-', + fileOrDir.isDirectory() ? 0 : fileOrDir.size(), + monthNumTo3LetterAbreviation(month, timeP->tm_mon), + dateTimeFormater(zero_prepended[0],timeP->tm_mday,'0'), + dateTimeFormater(zero_prepended[1],timeP->tm_hour,'0'), + dateTimeFormater(zero_prepended[2],timeP->tm_min,'0'), + fileOrDir.name()); fileOrDir.close(); } @@ -849,10 +864,8 @@ class FTPServer : public TCPServer #endif return false; } - return true; } - return false; }