You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2020/06/19 23:15:40 UTC

[commons-net] branch master updated: Improve ftp client MLST command compatibility

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new a61b111  Improve ftp client MLST command compatibility
     new c72538b  Merge pull request #45 from yddgit/master
a61b111 is described below

commit a61b111502aef396230de4d94358d883c3611df0
Author: yang <64...@qq.com>
AuthorDate: Mon Nov 4 23:02:58 2019 +0800

    Improve ftp client MLST command compatibility
---
 src/main/java/org/apache/commons/net/ftp/FTPClient.java | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClient.java b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
index 94cd7ff..81f86fb 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -2544,14 +2544,17 @@ implements Configurable
         boolean success = FTPReply.isPositiveCompletion(sendCommand(FTPCmd.MLST, pathname));
         if (success){
             String reply = getReplyStrings()[1];
+            // some FTP server reply not contains space before fact(s)
+            if(reply.charAt(0) != ' ') { reply = " " + reply; }
             /* check the response makes sense.
              * Must have space before fact(s) and between fact(s) and file name
              * Fact(s) can be absent, so at least 3 chars are needed.
              */
-            if (reply.length() < 3 || reply.charAt(0) != ' ') {
+            if (reply.length() < 3) {
                 throw new MalformedServerReplyException("Invalid server reply (MLST): '" + reply + "'");
             }
-            String entry = reply.substring(1); // skip leading space for parser
+            // some FTP server reply contains more than one space before fact(s)
+            String entry = reply.replaceAll("^\\s+", ""); // skip leading space for parser
             return MLSxEntryParser.parseEntry(entry);
         } else {
             return null;