From 15cc91c090b6175896949c9f3d104c897eea5408 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 19 Feb 2025 20:01:05 -0500 Subject: [PATCH] FTPClientExample uses the wrong FTP system type to parse file lines For example, when connecting to Microsoft ISS FTP on Windows 10.0.19045.5371, the FTPClientExample thought it was connected to a Unix system which caused it not be able to parse file lines --- src/changes/changes.xml | 1 + .../net/examples/ftp/FTPClientExample.java | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 78a2d2b80..42777ddc7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -85,6 +85,7 @@ The type attribute can be add,update,fix,remove. Deprecate FTPFileFilters.FTPFileFilters(). Avoid multiple possible NullPointerException in SocketClient.verifyRemote(Socket). PrintCommandListener.protocolReplyReceived(ProtocolCommandEvent) doesn't always use an end-of-line. + FTPClientExample uses the wrong FTP system type to parse file lines. Add org.apache.commons.net.nntp.Article#getChild(). Add org.apache.commons.net.nntp.Article#getNext(). diff --git a/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java b/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java index 17aaf830d..3d6910614 100644 --- a/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java +++ b/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java @@ -88,6 +88,18 @@ public final class FTPClientExample { + "\t-# - add hash display during transfers\n"; // @formatter:on + private static void configure(final FTPClient ftp, final FTPClientConfig config, final String defaultDateFormat, final String recentDateFormat, + final boolean saveUnparseable) { + config.setUnparseableEntries(saveUnparseable); + if (defaultDateFormat != null) { + config.setDefaultDateFormatStr(defaultDateFormat); + } + if (recentDateFormat != null) { + config.setRecentDateFormatStr(recentDateFormat); + } + ftp.configure(config); + } + private static CopyStreamListener createListener() { return new CopyStreamListener() { private long megsTotal; @@ -315,14 +327,7 @@ public static void main(final String[] args) throws UnknownHostException { } else { config = new FTPClientConfig(); } - config.setUnparseableEntries(saveUnparseable); - if (defaultDateFormat != null) { - config.setDefaultDateFormatStr(defaultDateFormat); - } - if (recentDateFormat != null) { - config.setRecentDateFormatStr(recentDateFormat); - } - ftp.configure(config); + configure(ftp, config, defaultDateFormat, recentDateFormat, saveUnparseable); try { final int reply; @@ -363,6 +368,9 @@ public static void main(final String[] args) throws UnknownHostException { } System.out.println("Remote system is " + ftp.getSystemType()); + if (!ftp.getSystemType().contains(config.getServerSystemKey())) { + configure(ftp, new FTPClientConfig(ftp.getSystemType()), defaultDateFormat, recentDateFormat, saveUnparseable); + } if (opts != null) { ftp.opts(opts); }