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

FTPClient.mlistFile returns null timestamps in FTPFile.getTimestamp

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 3.3
    • None
    • FTP
    • None
    • On Debian linux with proftpd server

    • Patch

    Description

      In FTPClient mlistFile("test.txt") :

      FTPClient.java
          public FTPFile mlistFile(String pathname) throws IOException
          {
              boolean success = FTPReply.isPositiveCompletion(sendCommand(FTPCmd.MLST, pathname));
              if (success){
                  String entry = getReplyStrings()[1].substring(1); // skip leading space for parser
                  return MLSxEntryParser.parseEntry(entry);
              } else {
                  return null;
              }
          }
      

      getReplyStrings() return :
      250-Start of list for test.txt
      250-modify=20150616133640;perm=adfrw;size=83752220;type=file;unique=23U8FE039C;UNIX.group=32;UNIX.mode=0644;UNIX.owner=2005; /data/test.txt
      250 End of list
      So getReplyStrings()[1].substring(1) return
      50-modify=20150616133640;perm=adfrw;size=83752220;type=file;unique=23U8FE039C;UNIX.group=32;UNIX.mode=0644;UNIX.owner=2005; /data/test.txt

      MLSxEntryParser.java
      public FTPFile parseFTPEntry(String entry) {
              String parts[] = entry.split(" ",2); // Path may contain space
              if (parts.length != 2) {
                  return null;
              }
              FTPFile file = new FTPFile();
              file.setRawListing(entry);
              file.setName(parts[1]);
              String[] facts = parts[0].split(";");
              boolean hasUnixMode = parts[0].toLowerCase(Locale.ENGLISH).contains("unix.mode=");
              for(String fact : facts) {
                  String []factparts = fact.split("=");
      // Sample missing permission
      // drwx------   2 mirror   mirror       4096 Mar 13  2010 subversion
      // modify=20100313224553;perm=;type=dir;unique=811U282598;UNIX.group=500;UNIX.mode=0700;UNIX.owner=500; subversion
                  if (factparts.length != 2) {
                      continue; // nothing to do here
                  }
                  String factname = factparts[0].toLowerCase(Locale.ENGLISH);
                  String factvalue = factparts[1];
                  String valueLowerCase = factvalue.toLowerCase(Locale.ENGLISH);
                  if ("size".equals(factname)) {
                      file.setSize(Long.parseLong(factvalue));
                  }
                  else if ("sizd".equals(factname)) { // Directory size
                      file.setSize(Long.parseLong(factvalue));
                  }
                  else if ("modify".equals(factname)) {
      (...)
      

      50-modify not correspond to modify, so the parser not find the date

      Possible patch :

      FTPClient.java
          public FTPFile mlistFile(String pathname) throws IOException
          {
              boolean success = FTPReply.isPositiveCompletion(sendCommand(FTPCmd.MLST, pathname));
              if (success){
                  String entry = getReplyStrings()[1].substring(4); // skip leading 
      (...)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            nleclerc78 Nicolas Leclerc
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: