summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Plasa <dplasa@gmail.com>2020-05-30 01:17:31 +0200
committerDaniel Plasa <dplasa@gmail.com>2020-05-30 01:17:31 +0200
commit4358b80d8a80f3c090c4b060a8c3d877c5a58bb4 (patch)
tree45ff7a613a760f49cea1ade03c9212d579da8ae7
parentuse a buffer size that only depends on the size of the lwip buffer config (diff)
downloadFTPCLientServer-4358b80d8a80f3c090c4b060a8c3d877c5a58bb4.tar
FTPCLientServer-4358b80d8a80f3c090c4b060a8c3d877c5a58bb4.tar.gz
FTPCLientServer-4358b80d8a80f3c090c4b060a8c3d877c5a58bb4.tar.bz2
FTPCLientServer-4358b80d8a80f3c090c4b060a8c3d877c5a58bb4.tar.lz
FTPCLientServer-4358b80d8a80f3c090c4b060a8c3d877c5a58bb4.tar.xz
FTPCLientServer-4358b80d8a80f3c090c4b060a8c3d877c5a58bb4.tar.zst
FTPCLientServer-4358b80d8a80f3c090c4b060a8c3d877c5a58bb4.zip
-rw-r--r--FTPServer.cpp53
1 files changed, 40 insertions, 13 deletions
diff --git a/FTPServer.cpp b/FTPServer.cpp
index ca224e8..51a9132 100644
--- a/FTPServer.cpp
+++ b/FTPServer.cpp
@@ -559,6 +559,15 @@ int8_t FTPServer::processCommand()
{
FTP_SEND_MSG(150, "Accepted data connection");
uint16_t dirCount = 0;
+
+ // filter out possible command parameters like "-a", given by some clients
+ // like FuseFS
+ int8_t dashPos = path.lastIndexOf(F("-"));
+ if (dashPos > 0)
+ {
+ path.remove(dashPos);
+ }
+ FTP_DEBUG_MSG("Listing content of >%s<", path.c_str());
Dir dir = THEFS.openDir(path);
while (dir.next())
{
@@ -568,24 +577,31 @@ int8_t FTPServer::processCommand()
if (cwd == FPSTR(aSlash) && fn[0] == '/')
fn.remove(0, 1);
isDir = dir.isDirectory();
+ file = dir.openFile("r");
+ String fileTime = makeDateTimeStr(file.getLastWrite());
+ file.close();
+
if (FTP_CMD(LIST) == command)
{
- if (isDir)
- {
- data.printf_P(PSTR("+d\r\n,\t%s\r\n"), fn.c_str());
- }
- else
- {
- data.printf_P(PSTR("+r,s%lu\r\n,\t%s\r\n"), (uint32_t)dir.fileSize(), fn.c_str());
- }
+ // unixperms type userid groupid size time & date name
+ // drwxrwsr-x 2 111 117 4096 Apr 01 12:45 aDirectory
+ // -rw-rw-r-- 1 111 117 875315 Mar 23 17:29 aFile
+ data.printf_P(PSTR("%crw%cr-%cr-%c %c 0 0 %8lu %s %s\r\n"),
+ isDir ? 'd' : '-',
+ isDir ? 'x' : '-',
+ isDir ? 'x' : '-',
+ isDir ? 'x' : '-',
+ isDir ? '2' : '1',
+ isDir ? 0 : (uint32_t)dir.fileSize(),
+ fileTime.c_str(),
+ fn.c_str());
+ //data.printf_P(PSTR("+r,s%lu\r\n,\t%s\r\n"), (uint32_t)dir.fileSize(), fn.c_str());
}
else if (FTP_CMD(MLSD) == command)
{
// "modify=20170122163911;type=dir;UNIX.group=0;UNIX.mode=0775;UNIX.owner=0; dirname"
// "modify=20170121000817;size=12;type=file;UNIX.group=0;UNIX.mode=0644;UNIX.owner=0; filename"
- file = dir.openFile("r");
- data.printf_P(PSTR("modify=%s;UNIX.group=0;UNIX.owner=0;UNIX.mode="), makeDateTimeStr(file.getLastWrite()).c_str());
- file.close();
+ data.printf_P(PSTR("modify=%s;UNIX.group=0;UNIX.owner=0;UNIX.mode="), fileTime.c_str());
if (isDir)
{
data.printf_P(PSTR("0755;type=dir; "));
@@ -1193,7 +1209,18 @@ String FTPServer::makeDateTimeStr(time_t ft)
{
struct tm *_tm = gmtime(&ft);
String tmp;
- tmp.reserve(17);
- strftime((char *)tmp.c_str(), 17, "%Y%m%d%H%M%S", _tm);
+ if (FTP_CMD(MLSD) == command)
+ {
+ tmp.reserve(17);
+ strftime((char *)tmp.c_str(), 17, "%Y%m%d%H%M%S", _tm);
+ }
+ else if (FTP_CMD(LIST) == command)
+ {
+ // "%h %d %H:%M" for file dates of the current year
+ // "%h %d %Y" for file dates of any other years
+ // FIXME ignore year for now...
+ tmp.reserve(13);
+ strftime((char *)tmp.c_str(), 13, "%h %d %H:%M", _tm);
+ }
return tmp;
}