You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/02/20 01:01:18 UTC
(commons-net) 08/08: FTPClientExample uses the wrong FTP system type to parse file lines
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git
commit 15cc91c090b6175896949c9f3d104c897eea5408
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Feb 19 20:01:05 2025 -0500
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 +
.../commons/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 78a2d2b8..42777ddc 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -85,6 +85,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate FTPFileFilters.FTPFileFilters().</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Avoid multiple possible NullPointerException in SocketClient.verifyRemote(Socket).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">PrintCommandListener.protocolReplyReceived(ProtocolCommandEvent) doesn't always use an end-of-line.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">FTPClientExample uses the wrong FTP system type to parse file lines.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.net.nntp.Article#getChild().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.net.nntp.Article#getNext().</action>
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 17aaf830..3d691061 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 final class FTPClientExample {
} 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 final class FTPClientExample {
}
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);
}