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:10 UTC
(commons-net) branch master updated (d8c1ab14 -> 15cc91c0)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git
from d8c1ab14 Add --OPTS to FTPClientExample
new c82aa29f Inline single-use local variable
new c3188586 Javadoc
new 65c424bb Import type instead of using a FQCN
new 944081ee Use camel case
new 77c27868 Reuse IOUtils
new 780595c7 Use an ArrayList instead of a Vector
new f06494ce Reuse IOUtils
new 15cc91c0 FTPClientExample uses the wrong FTP system type to parse file lines
The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/changes/changes.xml | 1 +
.../commons/net/examples/ftp/FTPClientExample.java | 24 ++++++----
.../java/org/apache/commons/net/ftp/FTPClient.java | 54 ++++++++++++++--------
.../parser/DefaultFTPFileEntryParserFactory.java | 26 +++++------
.../org/apache/commons/net/nntp/NNTPClient.java | 30 +++---------
5 files changed, 70 insertions(+), 65 deletions(-)
(commons-net) 02/08: Javadoc
Posted by gg...@apache.org.
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 c318858686fae66853dbc6952823495419a922d0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Feb 19 19:27:59 2025 -0500
Javadoc
---
.../java/org/apache/commons/net/ftp/FTPClient.java | 43 +++++++++++++++-------
1 file changed, 30 insertions(+), 13 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 8878f7a9..69411572 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -535,7 +535,7 @@ public class FTPClient extends FTP implements Configurable {
private int activeMaxPort;
private InetAddress activeExternalHost;
- /** Overrides __activeExternalHost in EPRT/PORT commands. */
+ /** Overrides activeExternalHost in EPRT/PORT commands. */
private InetAddress reportActiveExternalHost;
/** The address to bind to on passive connections, if necessary. */
@@ -553,7 +553,10 @@ public class FTPClient extends FTP implements Configurable {
private FTPFileEntryParserFactory parserFactory;
- private int bufferSize; // for buffered data streams
+ /**
+ * For buffered data streams.
+ */
+ private int bufferSize;
private int sendDataSocketBufferSize;
@@ -561,32 +564,46 @@ public class FTPClient extends FTP implements Configurable {
private boolean listHiddenFiles;
- private boolean useEPSVwithIPv4; // whether to attempt EPSV with an IPv4 connection
+ /**
+ * Whether to attempt EPSV with an IPv4 connection.
+ */
+ private boolean useEPSVwithIPv4;
- // __systemName is a cached value that should not be referenced directly
- // except when assigned in getSystemName and __initDefaults.
+ /**
+ * A cached value that should not be referenced directly except when assigned in getSystemName and initDefaults.
+ */
private String systemName;
- // __entryParser is a cached value that should not be referenced directly
- // except when assigned in listFiles(String, String) and __initDefaults.
+ /**
+ * A cached value that should not be referenced directly except when assigned in listFiles(String, String) and initDefaults.
+ */
private FTPFileEntryParser entryParser;
- // Key used to create the parser; necessary to ensure that the parser type is not ignored
+ /**
+ * Key used to create the parser; necessary to ensure that the parser type is not ignored.
+ */
private String entryParserKey;
private FTPClientConfig configuration;
- // Listener used by store/retrieve methods to handle keepalive
+ /**
+ * Listener used by store/retrieve methods to handle keepalive.
+ */
private CopyStreamListener copyStreamListener;
- // How long to wait before sending another control keep-alive message
+ /**
+ * How long to wait before sending another control keep-alive message.
+ */
private Duration controlKeepAliveTimeout = Duration.ZERO;
- // How long to wait for keepalive message replies before continuing
- // Most FTP servers don't seem to support concurrent control and data connection usage
+ /**
+ * How long to wait for keepalive message replies before continuing. Most FTP servers don't seem to support concurrent control and data connection usage.
+ */
private Duration controlKeepAliveReplyTimeout = Duration.ofSeconds(1);
- // Debug counts for NOOP acks
+ /**
+ * Debug counts for NOOP acks.
+ */
private int[] cslDebug;
/**
(commons-net) 04/08: Use camel case
Posted by gg...@apache.org.
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 944081ee4e202c92800f12297e430002ca4d8ea6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Feb 19 19:30:33 2025 -0500
Use camel case
---
.../parser/DefaultFTPFileEntryParserFactory.java | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java b/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
index 2d6cfa04..4fa00f3d 100644
--- a/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
+++ b/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
@@ -128,28 +128,28 @@ public class DefaultFTPFileEntryParserFactory implements FTPFileEntryParserFacto
}
if (parser == null) { // Now try for aliases
- final String ukey = key.toUpperCase(Locale.ENGLISH);
- if (ukey.contains(FTPClientConfig.SYST_UNIX_TRIM_LEADING)) {
+ final String upperKey = key.toUpperCase(Locale.ENGLISH);
+ if (upperKey.contains(FTPClientConfig.SYST_UNIX_TRIM_LEADING)) {
parser = new UnixFTPEntryParser(config, true);
}
// must check this after SYST_UNIX_TRIM_LEADING as it is a substring of it
- else if (ukey.contains(FTPClientConfig.SYST_UNIX)) {
+ else if (upperKey.contains(FTPClientConfig.SYST_UNIX)) {
parser = new UnixFTPEntryParser(config, false);
- } else if (ukey.contains(FTPClientConfig.SYST_VMS)) {
+ } else if (upperKey.contains(FTPClientConfig.SYST_VMS)) {
parser = new VMSVersioningFTPEntryParser(config);
- } else if (ukey.contains(FTPClientConfig.SYST_NT)) {
+ } else if (upperKey.contains(FTPClientConfig.SYST_NT)) {
parser = createNTFTPEntryParser(config);
- } else if (ukey.contains(FTPClientConfig.SYST_OS2)) {
+ } else if (upperKey.contains(FTPClientConfig.SYST_OS2)) {
parser = new OS2FTPEntryParser(config);
- } else if (ukey.contains(FTPClientConfig.SYST_OS400) || ukey.contains(FTPClientConfig.SYST_AS400)) {
+ } else if (upperKey.contains(FTPClientConfig.SYST_OS400) || upperKey.contains(FTPClientConfig.SYST_AS400)) {
parser = createOS400FTPEntryParser(config);
- } else if (ukey.contains(FTPClientConfig.SYST_MVS)) {
+ } else if (upperKey.contains(FTPClientConfig.SYST_MVS)) {
parser = new MVSFTPEntryParser(); // Does not currently support config parameter
- } else if (ukey.contains(FTPClientConfig.SYST_NETWARE)) {
+ } else if (upperKey.contains(FTPClientConfig.SYST_NETWARE)) {
parser = new NetwareFTPEntryParser(config);
- } else if (ukey.contains(FTPClientConfig.SYST_MACOS_PETER)) {
+ } else if (upperKey.contains(FTPClientConfig.SYST_MACOS_PETER)) {
parser = new MacOsPeterFTPEntryParser(config);
- } else if (ukey.contains(FTPClientConfig.SYST_L8)) {
+ } else if (upperKey.contains(FTPClientConfig.SYST_L8)) {
// L8 normally means Unix, but move it to the end for some L8 systems that aren't.
// This check should be last!
parser = new UnixFTPEntryParser(config);
(commons-net) 05/08: Reuse IOUtils
Posted by gg...@apache.org.
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 77c278687651a80dace5b5851c70341d7d860935
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Feb 19 19:50:14 2025 -0500
Reuse IOUtils
---
src/main/java/org/apache/commons/net/ftp/FTPClient.java | 11 ++++-------
1 file changed, 4 insertions(+), 7 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 69411572..1aa343c4 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -18,7 +18,6 @@ package org.apache.commons.net.ftp;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
@@ -42,6 +41,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Random;
@@ -2396,16 +2396,13 @@ public class FTPClient extends FTP implements Configurable {
* @throws IOException If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
*/
public String[] listNames(final String path) throws IOException {
- final ArrayList<String> results = new ArrayList<>();
+ final List<String> results;
try (Socket socket = _openDataConnection_(FTPCmd.NLST, getListArguments(path))) {
if (socket == null) {
return null;
}
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()))) {
- String line;
- while ((line = reader.readLine()) != null) {
- results.add(line);
- }
+ try (InputStream in = socket.getInputStream()) {
+ results = IOUtils.readLines(in, getControlEncoding());
}
}
if (completePendingCommand()) {
(commons-net) 06/08: Use an ArrayList instead of a Vector
Posted by gg...@apache.org.
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 780595c7dbcb85f0afa9dd9bd71f354134f23237
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Feb 19 19:54:13 2025 -0500
Use an ArrayList instead of a Vector
- Reuse IOUtils
- Simplify
---
.../org/apache/commons/net/nntp/NNTPClient.java | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
index d9d02f5d..84d42d5f 100644
--- a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
+++ b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
@@ -23,8 +23,10 @@ import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
+import java.util.List;
import java.util.Vector;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.net.MalformedServerReplyException;
import org.apache.commons.net.io.DotTerminatedMessageReader;
import org.apache.commons.net.io.DotTerminatedMessageWriter;
@@ -436,25 +438,11 @@ public class NNTPClient extends NNTP {
if (!NNTPReply.isPositiveCompletion(newnews(query.getNewsgroups(), query.getDate(), query.getTime(), query.isGMT(), query.getDistributions()))) {
return null;
}
-
- final Vector<String> list = new Vector<>();
+ List<String> list = new ArrayList<>();
try (BufferedReader reader = new DotTerminatedMessageReader(_reader_)) {
-
- String line;
- while ((line = reader.readLine()) != null) {
- list.addElement(line);
- }
+ list = IOUtils.readLines(reader);
}
-
- final int size = list.size();
- if (size < 1) {
- return NetConstants.EMPTY_STRING_ARRAY;
- }
-
- final String[] result = new String[size];
- list.copyInto(result);
-
- return result;
+ return list.toArray(NetConstants.EMPTY_STRING_ARRAY);
}
/**
(commons-net) 08/08: FTPClientExample uses the wrong FTP system type to parse file lines
Posted by gg...@apache.org.
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);
}
(commons-net) 03/08: Import type instead of using a FQCN
Posted by gg...@apache.org.
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 65c424bbf70aa417080885c0d9cef0f0a2a833a2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Feb 19 19:29:22 2025 -0500
Import type instead of using a FQCN
---
.../commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java b/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
index b8021c1d..2d6cfa04 100644
--- a/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
+++ b/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
@@ -17,6 +17,7 @@
package org.apache.commons.net.ftp.parser;
+import java.util.Locale;
import java.util.regex.Pattern;
import org.apache.commons.net.ftp.Configurable;
@@ -127,7 +128,7 @@ public class DefaultFTPFileEntryParserFactory implements FTPFileEntryParserFacto
}
if (parser == null) { // Now try for aliases
- final String ukey = key.toUpperCase(java.util.Locale.ENGLISH);
+ final String ukey = key.toUpperCase(Locale.ENGLISH);
if (ukey.contains(FTPClientConfig.SYST_UNIX_TRIM_LEADING)) {
parser = new UnixFTPEntryParser(config, true);
}
(commons-net) 07/08: Reuse IOUtils
Posted by gg...@apache.org.
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 f06494cec0a1cbcfa6d69368882d5bd10e5ffa34
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Feb 19 19:55:52 2025 -0500
Reuse IOUtils
---
src/main/java/org/apache/commons/net/nntp/NNTPClient.java | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
index 84d42d5f..f8305bc0 100644
--- a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
+++ b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
@@ -515,14 +515,8 @@ public class NNTPClient extends NNTP {
if (!NNTPReply.isPositiveCompletion(sendCommand("LIST", "OVERVIEW.FMT"))) {
return null;
}
-
try (BufferedReader reader = new DotTerminatedMessageReader(_reader_)) {
- String line;
- final ArrayList<String> list = new ArrayList<>();
- while ((line = reader.readLine()) != null) {
- list.add(line);
- }
- return list.toArray(NetConstants.EMPTY_STRING_ARRAY);
+ return IOUtils.readLines(reader).toArray(NetConstants.EMPTY_STRING_ARRAY);
}
}
(commons-net) 01/08: Inline single-use local variable
Posted by gg...@apache.org.
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 c82aa29fc558be935df640aa2d600b97d8b4b8d8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Feb 19 19:15:38 2025 -0500
Inline single-use local variable
---
.../commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java b/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
index 9226bdb2..b8021c1d 100644
--- a/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
+++ b/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
@@ -64,8 +64,7 @@ public class DefaultFTPFileEntryParserFactory implements FTPFileEntryParserFacto
*/
@Override
public FTPFileEntryParser createFileEntryParser(final FTPClientConfig config) throws ParserInitializationException {
- final String key = config.getServerSystemKey();
- return createFileEntryParser(key, config);
+ return createFileEntryParser(config.getServerSystemKey(), config);
}
/**