Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-449

listFiles bug with folder that begins with "-"

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1
    • 3.2
    • FTP
    • None

    Description

      FTP Server status:

      root@xxx-srv:/data/Library# tree -A
      .
      ├── -dash
      │   ├── -dash.txt
      │   ├── file1.txt
      │   └── file2.txt
      └── test
          ├── file2.txt
          └── file.txt
      

      Test code:

       
      final FTPClient ftp = new FTPClient();
      ftp.connect(host, port);
      ftp.login(login, pwd);
      System.out.println("PWD: " + ftp.printWorkingDirectory());
      final FTPFile[] listFiles = ftp.listFiles();
      for (int i = 0; i < listFiles.length; i++) {
         System.out.println("[" + i + "] " + listFiles[i]);
      }
      
      System.out.println("Files in /-dash");
      final FTPFile[] listFiles2 = ftp.listFiles("/-dash");
      for (int i = 0; i < listFiles2.length; i++) {
         System.out.println("[" + i + "] " + listFiles2[i]);
      }
      
      System.out.println("Files in -dash");
      final FTPFile[] listFiles3 = ftp.listFiles("-dash");
      for (int i = 0; i < listFiles3.length; i++) {
         System.out.println("[" + i + "] " + listFiles3[i]);
      }
      

      results:

       
      PWD: /
      [0] -dash
      [1] test
      Files in /-dash
      [0] -dash.txt
      [1] file1.txt
      [2] file2.txt
      Files in -dash
      [0] -dash
      [1] .
      [2] ..
      [3] test
      

      When listing "-dash", it list the current directory instead of the destination one.
      If I do the same test with the folder test, this time it works as expected.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            sverger Stéphane Verger
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment