Server working but directory always empty

Home Forums The libraries hosted on the site FTP Server (Simple and Multi) Server working but directory always empty

Viewing 4 reply threads
  • Author
    Posts
    • #32300
      monaco87
      Participant

        Hi,

        I have an ESP32 application which logs to a LittleFS root. Each time the log file is updated I send a directory listing to the serial port and I can see the file under “/” and its size, which has increased.

        When I connect to the FTP server and “dir” or “ls” I get:

        227 Entering Passive Mode (192,168,XXXXXXXXXX)
        150 Accepted data connection to port 50009
        226 0 matches total

        “pwd” shows that I am indeed in “/”

        Any ideas?

      • #32315
        Renzo Mischianti
        Keymaster

          Hi Monaco,
          I tried It, and it seems to work. Can you explain the step you did?
          Bye Renzo

        • #32318
          monaco87
          Participant

            Hi, thanks for replying.

            Setup:

            
            #define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_LITTLEFS
            #include <SimpleFtpServer.h>
            FtpServer ftpSrv;
            
            void setup()
            {
                Serial.begin(115200);
                if (!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED))
                {
                    Serial.println("LittleFS Mount Failed");
                }
                else
                {
                    Serial.println("LittleFS Mounted OK");
                }
            
                delay(3000);
            }
            

            Code to create test file and list FS contents:

            
            void updateTestFile(String data)
            {
                if (!LittleFS.exists("/ign_log.txt"))
                {
                    File file = LittleFS.open("/ign_log.txt", FILE_WRITE);
                    if (!file)
                    {
                        Serial.println("There was an error opening ign_log.txt for writing");
                        return;
                    }
                    file.close();
                }
            
                File file = LittleFS.open("/ign_log.txt", FILE_APPEND);
                if (!file)
                {
                    Serial.println("- failed to open file for appending");
                    return;
                }
                if (file.print(data))
                {
                    Serial.println("- data appended");
                }
                else
                {
                    Serial.println("- append failed");
                }
                file.close();
            
                getFileList();
            }
            
            void getFileList()
            {
                Serial.printf("Listing directory: %s\r\n", "/");
            
                File root = LittleFS.open("/");
                if (!root)
                {
                    Serial.println("- failed to open directory");
                    return;
                }
                if (!root.isDirectory())
                {
                    Serial.println(" - not a directory");
                    return;
                }
            
                File file = root.openNextFile();
                while (file)
                {
                    if (file.isDirectory())
                    {
                        Serial.print("  DIR : ");
                        Serial.println(file.name());
                        // if (levels)
                        // {
                        //     listDir(SPIFFS, file.path(), levels - 1);
                        // }
                    }
                    else
                    {
                        Serial.print("  FILE: ");
                        Serial.print(file.name());
                        Serial.print("\tSIZE: ");
                        Serial.println(file.size());
                    }
                    file = root.openNextFile();
                }
            }
            

            Then the loop:

            
                ftpSrv.begin("abc","abc");
                while (true)
                {
                  ftpSrv.handleFTP();
                }
            

            getFileList() displays the test file and size on the serial console.

            I then manually ftp to the device from a bash shell, connection and login are fine. Commands ‘dir’ and ‘ls’ give zero files.

            Partition is default 4MB sith SPIFFS (12.MB APP, 1.5MB SPIFFS)

            • This reply was modified 8 months ago by monaco87.
            • This reply was modified 8 months ago by monaco87.
            • This reply was modified 8 months ago by monaco87.
          • #32323
            Renzo Mischianti
            Keymaster

              Hi monaco,
              modify #define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_LITTLEFS
              directly in SimpleFTPServerKey.h it can’t manage from the external.
              Bye Renzo

            • #32327
              monaco87
              Participant

                Renzo,

                Thank you very much, that fixed it – dumb mistake on my part.

                Thanks for the great software and the great help !

            Viewing 4 reply threads
            • You must be logged in to reply to this topic.
            Exit mobile version