summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Plasa <dplasa@gmail.com>2020-05-31 11:14:56 +0200
committerDaniel Plasa <dplasa@gmail.com>2020-05-31 11:14:56 +0200
commit8f92ad920684fe360c4a8669dffecc19176ff793 (patch)
tree4004e49b6e148ef4f59259c30986da51c387d14f
parenttested against 2.7.1 esp8266 core (diff)
downloadFTPCLientServer-8f92ad920684fe360c4a8669dffecc19176ff793.tar
FTPCLientServer-8f92ad920684fe360c4a8669dffecc19176ff793.tar.gz
FTPCLientServer-8f92ad920684fe360c4a8669dffecc19176ff793.tar.bz2
FTPCLientServer-8f92ad920684fe360c4a8669dffecc19176ff793.tar.lz
FTPCLientServer-8f92ad920684fe360c4a8669dffecc19176ff793.tar.xz
FTPCLientServer-8f92ad920684fe360c4a8669dffecc19176ff793.tar.zst
FTPCLientServer-8f92ad920684fe360c4a8669dffecc19176ff793.zip
-rw-r--r--FTPServer.cpp40
1 files changed, 17 insertions, 23 deletions
diff --git a/FTPServer.cpp b/FTPServer.cpp
index 7b99017..c521691 100644
--- a/FTPServer.cpp
+++ b/FTPServer.cpp
@@ -117,10 +117,6 @@ void FTPServer::handleFTP()
// V
// cProcess
//
-
- // if ((int32_t)(millisDelay - millis()) > 0)
- // return;
-
if (cmdState == cInit)
{
if (control.connected())
@@ -1177,52 +1173,50 @@ String FTPServer::getFileName(const String &param, bool fullFilePath)
return tmp;
}
-// Formats YYYYMMDDHHMMSS from a time_t timestamp
-//
-// uses the buf of the FTPServer to store the date string
//
-// parameters:
-// timestamp
+// Formats printable String from a time_t timestamp
//
-// return:
-// pointer to buf[0]
-
String FTPServer::makeDateTimeStr(time_t ft)
{
String tmp;
+ // a buffer with enough space for the formats
+ char buf[25];
+ char *b = buf;
+
+ // break down the provided file time
struct tm _tm;
gmtime_r(&ft, &_tm);
if (FTP_CMD(MLSD) == command)
{
- tmp.reserve(17);
- strftime((char *)tmp.c_str(), 17, "%Y%m%d%H%M%S", &_tm);
+ // "%Y%m%d%H%M%S", e.g. "20200517123400"
+ strftime(b, sizeof(buf), "%Y%m%d%H%M%S", &_tm);
}
else if (FTP_CMD(LIST) == command)
{
// "%h %d %H:%M", e.g. "May 17 12:34" for file dates of the current year
// "%h %d %Y" , e.g. "May 17 2019" for file dates of any other years
- tmp.reserve(18);
- // just convert both ways, cut out later what's to be shown
- strftime((char *)tmp.c_str(), 13, "%h %d %Y%H:%M", &_tm);
+ // just convert both ways, select later what's to be shown
+ // buf becomes "May 17 2019May 17 12:34"
+ strftime(b, sizeof(buf), "%h %d %H:%M%h %d %Y", &_tm);
// check for a year != year from now
int fileYear = _tm.tm_year;
time_t nowTime = time(NULL);
gmtime_r(&nowTime, &_tm);
- // tmp is "May 17 201912:34"
- if (fileYear != _tm.tm_year)
+ if (fileYear == _tm.tm_year)
{
- // cut off time
- tmp.remove(12);
+ // cut off 2nd half - year variant
+ b[12] = '\0';
}
else
{
- // cut off year
- tmp.remove(7,5);
+ // skip 1st half - time variant
+ b += 12;
}
}
+ tmp = b;
return tmp;
}