Skip to content

Commit

Permalink
FTPClientExample uses the wrong FTP system type to parse file lines
Browse files Browse the repository at this point in the history
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
  • Loading branch information
garydgregory committed Feb 20, 2025
1 parent f06494c commit 15cc91c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 15cc91c

Please sign in to comment.