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/16 17:14:26 UTC

(commons-net) branch master updated (5d3cf213 -> 257b1b5e)

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 5d3cf213 Use Java 6 API for exception construction
     new f80f9639 Add FTPCmd.OPTS
     new e3742234 Javadoc
     new 2341e876 Reuse IOUtils
     new 19f5d82b Avoid multiple possible NullPointerException in SocketClient.verifyRemote(Socket)
     new 4b5ac366 Reuse IOUtils
     new 7046ea5f Javadoc
     new 27742fb0 Fix test
     new def196b2 Better parameter names
     new c1a0ef0a Javadoc
     new 1a4e54ce Use String.join()
     new a45b091f Remove "__" prefix from local variable names
     new e0c54a74 PrintCommandListener.protocolReplyReceived(ProtocolCommandEvent) doesn't always use an end-of-line.
     new a93879ea Internal refactoring for a magic char
     new 0875c042 Reduce vertical whitespace
     new 257b1b5e Add FTP.opts(String, String)

The 15 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                            |   6 +-
 .../apache/commons/net/PrintCommandListener.java   |  10 +-
 .../apache/commons/net/ProtocolCommandSupport.java |   9 +-
 .../java/org/apache/commons/net/SocketClient.java  |  59 ++++---
 .../org/apache/commons/net/bsd/RCommandClient.java |   9 +-
 .../org/apache/commons/net/bsd/RExecClient.java    |  17 +-
 .../commons/net/examples/ftp/FTPClientExample.java |  10 +-
 .../commons/net/examples/ftp/TFTPExample.java      |  11 +-
 src/main/java/org/apache/commons/net/ftp/FTP.java  | 181 ++++++++++----------
 .../java/org/apache/commons/net/ftp/FTPClient.java | 186 ++++++++++-----------
 .../apache/commons/net/ftp/FTPClientConfig.java    |  14 +-
 .../java/org/apache/commons/net/ftp/FTPCmd.java    |   9 +-
 .../java/org/apache/commons/net/ftp/FTPFile.java   |   2 +-
 .../org/apache/commons/net/ftp/FTPHTTPClient.java  |   2 +-
 .../apache/commons/net/ftp/FTPListParseEngine.java |   2 -
 .../org/apache/commons/net/ftp/FTPSClient.java     |  20 +--
 .../commons/net/ftp/parser/MLSxEntryParser.java    |   4 +-
 .../java/org/apache/commons/net/imap/IMAP.java     |  20 +--
 .../apache/commons/net/io/CopyStreamListener.java  |  15 +-
 src/main/java/org/apache/commons/net/io/Util.java  |  21 +--
 .../java/org/apache/commons/net/nntp/NNTP.java     |  15 +-
 .../org/apache/commons/net/nntp/ReplyIterator.java |   8 +-
 .../java/org/apache/commons/net/pop3/POP3.java     |  15 +-
 .../java/org/apache/commons/net/smtp/SMTP.java     |  16 +-
 .../apache/commons/net/telnet/TelnetClient.java    |   2 +-
 .../apache/commons/net/util/KeyManagerUtils.java   |   4 +-
 .../commons/net/ftp/ListingFunctionalTest.java     |  40 +----
 27 files changed, 323 insertions(+), 384 deletions(-)


(commons-net) 11/15: Remove "__" prefix from local variable names

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 a45b091fb22d94346d5b654f4a47daeb7bc8e425
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 11:44:28 2025 -0500

    Remove "__" prefix from local variable names
    
    - Better use of StringBuilder API
    - Reduce vertical whitespace
---
 .../org/apache/commons/net/PrintCommandListener.java |  2 +-
 .../java/org/apache/commons/net/bsd/RExecClient.java |  8 +-------
 .../java/org/apache/commons/net/ftp/FTPClient.java   |  6 +++---
 .../java/org/apache/commons/net/ftp/FTPFile.java     |  2 +-
 .../org/apache/commons/net/ftp/FTPHTTPClient.java    |  2 +-
 src/main/java/org/apache/commons/net/imap/IMAP.java  | 20 ++++++++------------
 src/main/java/org/apache/commons/net/nntp/NNTP.java  | 15 +++++----------
 src/main/java/org/apache/commons/net/pop3/POP3.java  | 15 +++++----------
 src/main/java/org/apache/commons/net/smtp/SMTP.java  | 16 +++++-----------
 .../org/apache/commons/net/telnet/TelnetClient.java  |  2 +-
 .../commons/net/ftp/ListingFunctionalTest.java       |  1 +
 11 files changed, 32 insertions(+), 57 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/PrintCommandListener.java b/src/main/java/org/apache/commons/net/PrintCommandListener.java
index 95d304e7..51888441 100644
--- a/src/main/java/org/apache/commons/net/PrintCommandListener.java
+++ b/src/main/java/org/apache/commons/net/PrintCommandListener.java
@@ -139,7 +139,7 @@ public class PrintCommandListener implements ProtocolCommandListener {
         }
         final int pos = msg.indexOf(SocketClient.NETASCII_EOL);
         if (pos > 0) {
-            final StringBuilder sb = new StringBuilder();
+            final StringBuilder sb = new StringBuilder(msg + 1);
             sb.append(msg.substring(0, pos));
             sb.append(eolMarker);
             sb.append(msg.substring(pos));
diff --git a/src/main/java/org/apache/commons/net/bsd/RExecClient.java b/src/main/java/org/apache/commons/net/bsd/RExecClient.java
index a121bff7..ea85360b 100644
--- a/src/main/java/org/apache/commons/net/bsd/RExecClient.java
+++ b/src/main/java/org/apache/commons/net/bsd/RExecClient.java
@@ -183,14 +183,11 @@ public class RExecClient extends SocketClient {
      * @throws IOException If the rexec() attempt fails. The exception will contain a message indicating the nature of the failure.
      */
     public void rexec(final String user, final String password, final String command, final boolean separateErrorStream) throws IOException {
-        int ch;
-
         if (separateErrorStream) {
             _errorStream_ = createErrorStream();
         } else {
             _output_.write(NULL_CHAR);
         }
-
         _output_.write(user.getBytes(getCharset()));
         _output_.write(NULL_CHAR);
         _output_.write(password.getBytes(getCharset()));
@@ -198,15 +195,12 @@ public class RExecClient extends SocketClient {
         _output_.write(command.getBytes(getCharset()));
         _output_.write(NULL_CHAR);
         _output_.flush();
-
-        ch = _input_.read();
+        int ch = _input_.read();
         if (ch > 0) {
             final StringBuilder buffer = new StringBuilder();
-
             while ((ch = _input_.read()) != NetConstants.EOS && ch != '\n') {
                 buffer.append((char) ch);
             }
-
             throw new IOException(buffer.toString());
         }
         if (ch < 0) {
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 ca522a5a..0d4cf266 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -496,7 +496,7 @@ public class FTPClient extends FTP implements Configurable {
     static String parsePathname(final String reply) {
         final String param = reply.substring(REPLY_CODE_LEN + 1);
         if (param.startsWith("\"")) {
-            final StringBuilder sb = new StringBuilder();
+            final StringBuilder sb = new StringBuilder(param.length());
             boolean quoteSeen = false;
             // start after initial quote
             for (int i = 1; i < param.length(); i++) {
@@ -1627,7 +1627,7 @@ public class FTPClient extends FTP implements Configurable {
     /**
      * Gets the host address for active mode; allows the local address to be overridden.
      *
-     * @return __activeExternalHost if non-null, else getLocalAddress()
+     * @return activeExternalHost if non-null, else getLocalAddress()
      * @see #setActiveExternalIPAddress(String)
      */
     InetAddress getHostAddress() {
@@ -1733,7 +1733,7 @@ public class FTPClient extends FTP implements Configurable {
      *
      * Useful for FTP Client behind Firewall NAT.
      *
-     * @return __reportActiveExternalHost if non-null, else getHostAddress();
+     * @return reportActiveExternalHost if non-null, else getHostAddress();
      */
     InetAddress getReportHostAddress() {
         if (reportActiveExternalHost != null) {
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPFile.java b/src/main/java/org/apache/commons/net/ftp/FTPFile.java
index a8c31bcb..38d3a4d8 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPFile.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPFile.java
@@ -283,7 +283,7 @@ public class FTPFile implements Serializable {
     }
 
     private String permissionToString(final int access) {
-        final StringBuilder sb = new StringBuilder();
+        final StringBuilder sb = new StringBuilder(3);
         if (hasPermission(access, READ_PERMISSION)) {
             sb.append('r');
         } else {
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java b/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
index 644f5061..28bbf9f0 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
@@ -216,7 +216,7 @@ public class FTPHTTPClient extends FTPClient {
         code = resp.substring(9, 12);
 
         if (!"200".equals(code)) {
-            final StringBuilder msg = new StringBuilder();
+            final StringBuilder msg = new StringBuilder(256);
             msg.append("HTTPTunnelConnector: connection failed\r\n");
             msg.append("Response received from the proxy:\r\n");
             for (final String line : response) {
diff --git a/src/main/java/org/apache/commons/net/imap/IMAP.java b/src/main/java/org/apache/commons/net/imap/IMAP.java
index 3a426150..b0a363f7 100644
--- a/src/main/java/org/apache/commons/net/imap/IMAP.java
+++ b/src/main/java/org/apache/commons/net/imap/IMAP.java
@@ -389,25 +389,21 @@ public class IMAP extends SocketClient {
      * @return The server reply code (either {@link IMAPReply#OK}, {@link IMAPReply#NO} or {@link IMAPReply#BAD}).
      */
     private int sendCommandWithID(final String commandID, final String command, final String args) throws IOException {
-        final StringBuilder __commandBuffer = new StringBuilder();
+        final StringBuilder builder = new StringBuilder();
         if (commandID != null) {
-            __commandBuffer.append(commandID);
-            __commandBuffer.append(' ');
+            builder.append(commandID);
+            builder.append(' ');
         }
-        __commandBuffer.append(command);
-
+        builder.append(command);
         if (args != null) {
-            __commandBuffer.append(' ');
-            __commandBuffer.append(args);
+            builder.append(' ');
+            builder.append(args);
         }
-        __commandBuffer.append(NETASCII_EOL);
-
-        final String message = __commandBuffer.toString();
+        builder.append(NETASCII_EOL);
+        final String message = builder.toString();
         __writer.write(message);
         __writer.flush();
-
         fireCommandSent(command, message);
-
         getReply();
         return replyCode;
     }
diff --git a/src/main/java/org/apache/commons/net/nntp/NNTP.java b/src/main/java/org/apache/commons/net/nntp/NNTP.java
index 69047ef5..61810827 100644
--- a/src/main/java/org/apache/commons/net/nntp/NNTP.java
+++ b/src/main/java/org/apache/commons/net/nntp/NNTP.java
@@ -640,21 +640,16 @@ public class NNTP extends SocketClient {
      * @throws IOException                   If an I/O error occurs while either sending the command or receiving the server reply.
      */
     public int sendCommand(final String command, final String args) throws IOException {
-        final StringBuilder __commandBuffer = new StringBuilder();
-        __commandBuffer.append(command);
-
+        final StringBuilder builder = new StringBuilder(command);
         if (args != null) {
-            __commandBuffer.append(' ');
-            __commandBuffer.append(args);
+            builder.append(' ');
+            builder.append(args);
         }
-        __commandBuffer.append(NETASCII_EOL);
-
+        builder.append(NETASCII_EOL);
         final String message;
-        _writer_.write(message = __commandBuffer.toString());
+        _writer_.write(message = builder.toString());
         _writer_.flush();
-
         fireCommandSent(command, message);
-
         return getReply();
     }
 
diff --git a/src/main/java/org/apache/commons/net/pop3/POP3.java b/src/main/java/org/apache/commons/net/pop3/POP3.java
index c9755819..a0ddd72b 100644
--- a/src/main/java/org/apache/commons/net/pop3/POP3.java
+++ b/src/main/java/org/apache/commons/net/pop3/POP3.java
@@ -275,21 +275,16 @@ public class POP3 extends SocketClient {
         if (writer == null) {
             throw new IllegalStateException("Socket is not connected");
         }
-        final StringBuilder __commandBuffer = new StringBuilder();
-        __commandBuffer.append(command);
-
+        final StringBuilder builder = new StringBuilder(command);
         if (args != null) {
-            __commandBuffer.append(' ');
-            __commandBuffer.append(args);
+            builder.append(' ');
+            builder.append(args);
         }
-        __commandBuffer.append(NETASCII_EOL);
-
-        final String message = __commandBuffer.toString();
+        builder.append(NETASCII_EOL);
+        final String message = builder.toString();
         writer.write(message);
         writer.flush();
-
         fireCommandSent(command, message);
-
         getReply();
         return replyCode;
     }
diff --git a/src/main/java/org/apache/commons/net/smtp/SMTP.java b/src/main/java/org/apache/commons/net/smtp/SMTP.java
index ee6e7cf6..62d3f4fb 100644
--- a/src/main/java/org/apache/commons/net/smtp/SMTP.java
+++ b/src/main/java/org/apache/commons/net/smtp/SMTP.java
@@ -516,24 +516,18 @@ public class SMTP extends SocketClient {
      * @throws IOException
      */
     private int sendCommand(final String command, final String args, final boolean includeSpace) throws IOException {
-        final StringBuilder __commandBuffer = new StringBuilder();
-        __commandBuffer.append(command);
-
+        final StringBuilder builder = new StringBuilder(command);
         if (args != null) {
             if (includeSpace) {
-                __commandBuffer.append(' ');
+                builder.append(' ');
             }
-            __commandBuffer.append(args);
+            builder.append(args);
         }
-
-        __commandBuffer.append(NETASCII_EOL);
-
-        final String message = __commandBuffer.toString();
+        builder.append(NETASCII_EOL);
+        final String message = builder.toString();
         writer.write(message);
         writer.flush();
-
         fireCommandSent(command, message);
-
         return getReply();
     }
 
diff --git a/src/main/java/org/apache/commons/net/telnet/TelnetClient.java b/src/main/java/org/apache/commons/net/telnet/TelnetClient.java
index b956235a..c1145ed0 100644
--- a/src/main/java/org/apache/commons/net/telnet/TelnetClient.java
+++ b/src/main/java/org/apache/commons/net/telnet/TelnetClient.java
@@ -109,7 +109,7 @@ public class TelnetClient extends Telnet {
         if (readerThread) {
             tmp.start();
         }
-        // __input CANNOT refer to the TelnetInputStream. We run into
+        // input CANNOT refer to the TelnetInputStream. We run into
         // blocking problems when some classes use TelnetInputStream, so
         // we wrap it with a BufferedInputStream which we know is safe.
         // This blocking behavior requires further investigation, but right
diff --git a/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java b/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
index 0487c385..e18b775a 100644
--- a/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
@@ -120,6 +120,7 @@ public class ListingFunctionalTest extends TestCase {
         client.connect(hostName);
         client.login("anonymous", "anonymous");
         client.enterLocalPassiveMode();
+        client.setAutodetectUTF8(true);
         client.addProtocolCommandListener(new PrintCommandListener(System.out));
     }
 


(commons-net) 10/15: Use String.join()

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 1a4e54ce63e73c92850fcd6fca69b7bd46fe7bf4
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 11:13:21 2025 -0500

    Use String.join()
    
    - Use Java style, not C
    - Reduce vertical whitespace
---
 src/main/java/org/apache/commons/net/ftp/FTP.java  | 33 ++--------------------
 .../apache/commons/net/ftp/FTPListParseEngine.java |  2 --
 2 files changed, 3 insertions(+), 32 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/ftp/FTP.java b/src/main/java/org/apache/commons/net/ftp/FTP.java
index 68cdd738..4f87dde1 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTP.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTP.java
@@ -518,17 +518,13 @@ public class FTP extends SocketClient {
     public int eprt(final InetAddress host, final int port) throws IOException {
         final int num;
         final StringBuilder info = new StringBuilder();
-        String h;
-
         // If IPv6, trim the zone index
-        h = host.getHostAddress();
+        String h = host.getHostAddress();
         num = h.indexOf('%');
         if (num > 0) {
             h = h.substring(0, num);
         }
-
         info.append("|");
-
         if (host instanceof Inet4Address) {
             info.append("1");
         } else if (host instanceof Inet6Address) {
@@ -539,7 +535,6 @@ public class FTP extends SocketClient {
         info.append("|");
         info.append(port);
         info.append("|");
-
         return sendCommand(FTPCmd.EPRT, info.toString());
     }
 
@@ -603,23 +598,18 @@ public class FTP extends SocketClient {
 
     private int getReply(final boolean reportReply) throws IOException {
         final int length;
-
         _newReplyString = true;
         _replyLines.clear();
-
         String line = _controlInput_.readLine();
-
         if (line == null) {
             throw new FTPConnectionClosedException("Connection closed without indication.");
         }
-
         // In case we run into an anomaly we don't want fatal index exceptions
         // to be thrown.
         length = line.length();
         if (length < REPLY_CODE_LEN) {
             throw new MalformedServerReplyException("Truncated server reply: " + line);
         }
-
         String code;
         try {
             code = line.substring(0, REPLY_CODE_LEN);
@@ -627,9 +617,7 @@ public class FTP extends SocketClient {
         } catch (final NumberFormatException e) {
             throw new MalformedServerReplyException("Could not parse response code.\nServer Reply: " + line);
         }
-
         _replyLines.add(line);
-
         // Check the server reply type
         if (length > REPLY_CODE_LEN) {
             final char sep = line.charAt(REPLY_CODE_LEN);
@@ -637,18 +625,14 @@ public class FTP extends SocketClient {
             if (sep == '-') {
                 do {
                     line = _controlInput_.readLine();
-
                     if (line == null) {
                         throw new FTPConnectionClosedException("Connection closed without indication.");
                     }
-
                     _replyLines.add(line);
-
                     // The length() check handles problems that could arise from readLine()
                     // returning too soon after encountering a naked CR or some other
                     // anomaly.
                 } while (isStrictMultilineParsing() ? strictCheck(line, code) : lenientCheck(line));
-
             } else if (isStrictReplyParsing()) {
                 if (length == REPLY_CODE_LEN + 1) { // expecting some text
                     throw new MalformedServerReplyException("Truncated server reply: '" + line + "'");
@@ -660,11 +644,9 @@ public class FTP extends SocketClient {
         } else if (isStrictReplyParsing()) {
             throw new MalformedServerReplyException("Truncated server reply: '" + line + "'");
         }
-
         if (reportReply) {
             fireReplyReceived(_replyCode, getReplyString());
         }
-
         if (_replyCode == FTPReply.SERVICE_NOT_AVAILABLE) {
             throw new FTPConnectionClosedException("FTP response 421 received.  Server closed connection.");
         }
@@ -690,13 +672,8 @@ public class FTP extends SocketClient {
         if (!_newReplyString) {
             return _replyString;
         }
-        final StringBuilder buffer = new StringBuilder(256);
-        for (final String line : _replyLines) {
-            buffer.append(line);
-            buffer.append(NETASCII_EOL);
-        }
         _newReplyString = false;
-        return _replyString = buffer.toString();
+        return _replyString = String.join(NETASCII_EOL, _replyLines);
     }
 
     /**
@@ -1027,17 +1004,14 @@ public class FTP extends SocketClient {
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
     public int port(final InetAddress host, final int port) throws IOException {
-        int num;
         final StringBuilder info = new StringBuilder(24);
-
         info.append(host.getHostAddress().replace('.', ','));
-        num = port >>> 8;
+        int num = port >>> 8;
         info.append(',');
         info.append(num);
         info.append(',');
         num = port & 0xff;
         info.append(num);
-
         return sendCommand(FTPCmd.PORT, info.toString());
     }
 
@@ -1489,7 +1463,6 @@ public class FTP extends SocketClient {
         } else {
             arg.append(modeCharAt(formatOrByteSize));
         }
-
         return sendCommand(FTPCmd.TYPE, arg.toString());
     }
 
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPListParseEngine.java b/src/main/java/org/apache/commons/net/ftp/FTPListParseEngine.java
index 95041e3f..a947fdaa 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPListParseEngine.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPListParseEngine.java
@@ -241,9 +241,7 @@ public class FTPListParseEngine {
      */
     private void read(final InputStream inputStream, final String charsetName) throws IOException {
         try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charsets.toCharset(charsetName)))) {
-
             String line = parser.readNextEntry(reader);
-
             while (line != null) {
                 entries.add(line);
                 line = parser.readNextEntry(reader);


(commons-net) 15/15: Add FTP.opts(String, String)

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 257b1b5e114c57741f2f0bfe957aa3b5757294e0
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 12:06:03 2025 -0500

    Add FTP.opts(String, String)
---
 src/changes/changes.xml                                             | 1 +
 src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 86dc933b..131a0ef6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -92,6 +92,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add SubnetInfo.iterableAddressStrings().</action> 
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add SubnetInfo.streamAddressStrings().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add FTPCmd.OPTS.</action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">Add FTP.opts(String, String).</action>
       <!-- UPDATE -->
       <action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 70 to 81 #261, #278, #280, #285, #298, #293, #300.</action>
       <action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.17.0 #268, #273, #281.</action>
diff --git a/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java b/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
index e18b775a..bdf1129f 100644
--- a/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
@@ -117,11 +117,12 @@ public class ListingFunctionalTest extends TestCase {
     protected void setUp() throws Exception {
         super.setUp();
         client = new FTPClient();
+        client.addProtocolCommandListener(new PrintCommandListener(System.out));
         client.connect(hostName);
         client.login("anonymous", "anonymous");
         client.enterLocalPassiveMode();
         client.setAutodetectUTF8(true);
-        client.addProtocolCommandListener(new PrintCommandListener(System.out));
+        client.opts("UTF-8", "NLST");
     }
 
     /*


(commons-net) 03/15: 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 2341e8766ea6cbdb7658184d0e336b93953c4eb4
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 15 16:17:25 2025 -0500

    Reuse IOUtils
---
 .../java/org/apache/commons/net/SocketClient.java  | 29 ++++------------------
 1 file changed, 5 insertions(+), 24 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/SocketClient.java b/src/main/java/org/apache/commons/net/SocketClient.java
index b403019c..a2d340d3 100644
--- a/src/main/java/org/apache/commons/net/SocketClient.java
+++ b/src/main/java/org/apache/commons/net/SocketClient.java
@@ -17,7 +17,6 @@
 
 package org.apache.commons.net;
 
-import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -32,6 +31,8 @@ import java.util.Objects;
 import javax.net.ServerSocketFactory;
 import javax.net.SocketFactory;
 
+import org.apache.commons.io.IOUtils;
+
 /**
  * The SocketClient provides the basic operations that are required of client objects accessing sockets. It is meant to be subclassed to avoid having to rewrite
  * the same code over and over again to open a socket, close a socket, set timeouts, etc. Of special note is the {@link #setSocketFactory setSocketFactory }
@@ -195,26 +196,6 @@ public abstract class SocketClient {
         return Objects.requireNonNull(_output_, "OutputStream");
     }
 
-    private void closeQuietly(final Closeable close) {
-        if (close != null) {
-            try {
-                close.close();
-            } catch (final IOException e) {
-                // Ignored
-            }
-        }
-    }
-
-    private void closeQuietly(final Socket socket) {
-        if (socket != null) {
-            try {
-                socket.close();
-            } catch (final IOException e) {
-                // Ignored
-            }
-        }
-    }
-
     /**
      * Opens a Socket connected to a remote host at the current default port and originating from the current host at a system assigned port. Before returning,
      * {@link #_connectAction_ _connectAction_() } is called to perform connection initialization actions.
@@ -323,9 +304,9 @@ public abstract class SocketClient {
      */
     @SuppressWarnings("unused") // subclasses may throw IOException
     public void disconnect() throws IOException {
-        closeQuietly(_socket_);
-        closeQuietly(_input_);
-        closeQuietly(_output_);
+        IOUtils.closeQuietly(_socket_);
+        IOUtils.closeQuietly(_input_);
+        IOUtils.closeQuietly(_output_);
         _socket_ = null;
         _hostname_ = null;
         _input_ = null;


(commons-net) 02/15: 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 e3742234d49680a8bb8dea4fd04751600268f85b
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 15 16:04:55 2025 -0500

    Javadoc
---
 src/main/java/org/apache/commons/net/ftp/FTPCmd.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/net/ftp/FTPCmd.java b/src/main/java/org/apache/commons/net/ftp/FTPCmd.java
index 5e31ca30..ddf991e1 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPCmd.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPCmd.java
@@ -51,7 +51,7 @@ public enum FTPCmd {
     /** FTP command EPSV. */
     EPSV,
 
-    /** FTP command FEAT. */
+    /** FTP command <a href="https://datatracker.ietf.org/doc/html/rfc2389#section-3">FEAT</a>. */
     FEAT,
 
     /** FTP command HELP. */


(commons-net) 07/15: Fix test

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 27742fb041647c49349cf642085194fe86f2fc0a
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 10:41:00 2025 -0500

    Fix test
    
    Remove extra vertical whitespace
---
 .../apache/commons/net/PrintCommandListener.java   |  1 -
 .../commons/net/ftp/ListingFunctionalTest.java     | 38 +++-------------------
 2 files changed, 5 insertions(+), 34 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/PrintCommandListener.java b/src/main/java/org/apache/commons/net/PrintCommandListener.java
index f1390d8d..95d304e7 100644
--- a/src/main/java/org/apache/commons/net/PrintCommandListener.java
+++ b/src/main/java/org/apache/commons/net/PrintCommandListener.java
@@ -33,7 +33,6 @@ public class PrintCommandListener implements ProtocolCommandListener {
     private final PrintWriter writer;
     private final boolean nologin;
     private final char eolMarker;
-
     private final boolean directionMarker;
 
     /**
diff --git a/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java b/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
index 28b3b29f..0487c385 100644
--- a/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
@@ -24,6 +24,9 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.net.PrintCommandListener;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -59,19 +62,15 @@ public class ListingFunctionalTest extends TestCase {
         final Class<?> clasz = ListingFunctionalTest.class;
         final Method[] methods = clasz.getDeclaredMethods();
         final TestSuite allSuites = new TestSuite("FTP Listing Functional Test Suite");
-
         for (final String[] element : testData) {
             final TestSuite suite = new TestSuite(element[VALID_PARSERKEY] + " @ " + element[HOSTNAME]);
-
             for (final Method method : methods) {
                 if (method.getName().startsWith("test")) {
                     suite.addTest(new ListingFunctionalTest(method.getName(), element));
                 }
             }
-
             allSuites.addTest(suite);
         }
-
         return allSuites;
     }
 
@@ -98,21 +97,16 @@ public class ListingFunctionalTest extends TestCase {
     private boolean findByName(final List<?> fileList, final String string) {
         boolean found = false;
         final Iterator<?> iter = fileList.iterator();
-
         while (iter.hasNext() && !found) {
             final Object element = iter.next();
-
             if (element instanceof FTPFile) {
                 final FTPFile file = (FTPFile) element;
-
                 found = file.getName().equals(string);
             } else {
                 final String fileName = (String) element;
-
                 found = fileName.endsWith(string);
             }
         }
-
         return found;
     }
 
@@ -126,7 +120,7 @@ public class ListingFunctionalTest extends TestCase {
         client.connect(hostName);
         client.login("anonymous", "anonymous");
         client.enterLocalPassiveMode();
-//        client.addProtocolCommandListener(new PrintCommandListener(System.out));
+        client.addProtocolCommandListener(new PrintCommandListener(System.out));
     }
 
     /*
@@ -139,11 +133,9 @@ public class ListingFunctionalTest extends TestCase {
         } catch (final IOException e) {
             e.printStackTrace();
         }
-
         if (client.isConnected()) {
             client.disconnect();
         }
-
         client = null;
         super.tearDown();
     }
@@ -153,10 +145,8 @@ public class ListingFunctionalTest extends TestCase {
      */
     public void testInitiateListParsing() throws IOException {
         client.changeWorkingDirectory(validPath);
-
         final FTPListParseEngine engine = client.initiateListParsing();
         final List<FTPFile> files = Arrays.asList(engine.getNext(25));
-
         assertTrue(files.toString(), findByName(files, validFilename));
     }
 
@@ -166,7 +156,6 @@ public class ListingFunctionalTest extends TestCase {
     public void testInitiateListParsingWithPath() throws IOException {
         final FTPListParseEngine engine = client.initiateListParsing(validParserKey, validPath);
         final List<FTPFile> files = Arrays.asList(engine.getNext(25));
-
         assertTrue(files.toString(), findByName(files, validFilename));
     }
 
@@ -176,7 +165,6 @@ public class ListingFunctionalTest extends TestCase {
     public void testInitiateListParsingWithPathAndAutodetection() throws IOException {
         final FTPListParseEngine engine = client.initiateListParsing(validPath);
         final List<FTPFile> files = Arrays.asList(engine.getNext(25));
-
         assertTrue(files.toString(), findByName(files, validFilename));
     }
 
@@ -185,7 +173,6 @@ public class ListingFunctionalTest extends TestCase {
      */
     public void testInitiateListParsingWithPathAndAutodetectionButEmpty() throws IOException {
         final FTPListParseEngine engine = client.initiateListParsing(invalidPath);
-
         assertFalse(engine.hasNext());
     }
 
@@ -194,7 +181,6 @@ public class ListingFunctionalTest extends TestCase {
      */
     public void testInitiateListParsingWithPathAndIncorrectParser() throws IOException {
         final FTPListParseEngine engine = client.initiateListParsing(invalidParserKey, invalidPath);
-
         assertFalse(engine.hasNext());
     }
 
@@ -205,15 +191,12 @@ public class ListingFunctionalTest extends TestCase {
         final FTPClientConfig config = new FTPClientConfig(validParserKey);
         client.configure(config);
         final List<FTPFile> files = Arrays.asList(client.listFiles(validPath));
-
         assertTrue(files.toString(), findByName(files, validFilename));
     }
 
     public void testListFilesWithAutodection() throws IOException {
         client.changeWorkingDirectory(validPath);
-
         final List<FTPFile> files = Arrays.asList(client.listFiles());
-
         assertTrue(files.toString(), findByName(files, validFilename));
     }
 
@@ -223,11 +206,8 @@ public class ListingFunctionalTest extends TestCase {
     public void testListFilesWithIncorrectParser() throws IOException {
         final FTPClientConfig config = new FTPClientConfig(invalidParserKey);
         client.configure(config);
-
         final FTPFile[] files = client.listFiles(validPath);
-
         assertNotNull(files);
-
         // This may well fail, e.g. window parser for VMS listing
         assertArrayEquals("Expected empty array: " + Arrays.toString(files), new FTPFile[] {}, files);
     }
@@ -237,7 +217,6 @@ public class ListingFunctionalTest extends TestCase {
      */
     public void testListFilesWithPathAndAutodectionButEmpty() throws IOException {
         final FTPFile[] files = client.listFiles(invalidPath);
-
         assertEquals(0, files.length);
     }
 
@@ -246,7 +225,6 @@ public class ListingFunctionalTest extends TestCase {
      */
     public void testListFilesWithPathAndAutodetection() throws IOException {
         final List<FTPFile> files = Arrays.asList(client.listFiles(validPath));
-
         assertTrue(files.toString(), findByName(files, validFilename));
     }
 
@@ -255,13 +233,9 @@ public class ListingFunctionalTest extends TestCase {
      */
     public void testListNames() throws IOException {
         client.changeWorkingDirectory(validPath);
-
         final String[] names = client.listNames();
-
         assertNotNull(names);
-
         final List<String> lnames = Arrays.asList(names);
-
         assertTrue(lnames.toString(), lnames.contains(validFilename));
     }
 
@@ -272,14 +246,12 @@ public class ListingFunctionalTest extends TestCase {
         final String[] listNames = client.listNames(validPath);
         assertNotNull("listNames not null", listNames);
         final List<String> names = Arrays.asList(listNames);
-
         assertTrue(names.toString(), findByName(names, validFilename));
     }
 
     public void testListNamesWithPathButEmpty() throws IOException {
         final String[] names = client.listNames(invalidPath);
-
-        assertNull(names);
+        assertTrue(ArrayUtils.isEmpty(names));
     }
 
     public void testPrintWorkingDirectory() throws IOException {


(commons-net) 14/15: Reduce vertical whitespace

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 0875c0427ac0df840530b1d86a62160d5b1ed27e
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 12:05:17 2025 -0500

    Reduce vertical whitespace
---
 src/main/java/org/apache/commons/net/ProtocolCommandSupport.java | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java b/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
index b1926e86..6da3561f 100644
--- a/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
+++ b/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.commons.net;
 
 import java.io.ObjectInputStream;
@@ -28,12 +27,11 @@ import org.apache.commons.net.util.ListenerList;
  * ProtocolCommandSupport is a convenience class for managing a list of ProtocolCommandListeners and firing ProtocolCommandEvents. You can simply delegate
  * ProtocolCommandEvent firing and listener registering/unregistering tasks to this class.
  *
- *
  * @see ProtocolCommandEvent
  * @see ProtocolCommandListener
  */
-
 public class ProtocolCommandSupport implements Serializable {
+
     private static final long serialVersionUID = -8017692739988399978L;
 
     /**
@@ -74,9 +72,7 @@ public class ProtocolCommandSupport implements Serializable {
      */
     public void fireCommandSent(final String command, final String message) {
         final ProtocolCommandEvent event;
-
         event = new ProtocolCommandEvent(source, command, message);
-
         for (final EventListener listener : listeners) {
             ((ProtocolCommandListener) listener).protocolCommandSent(event);
         }
@@ -94,7 +90,6 @@ public class ProtocolCommandSupport implements Serializable {
     public void fireReplyReceived(final int replyCode, final String message) {
         final ProtocolCommandEvent event;
         event = new ProtocolCommandEvent(source, replyCode, message);
-
         for (final EventListener listener : listeners) {
             ((ProtocolCommandListener) listener).protocolReplyReceived(event);
         }
@@ -117,7 +112,6 @@ public class ProtocolCommandSupport implements Serializable {
     private void readObject(final ObjectInputStream ignored) {
         throw new UnsupportedOperationException("Serialization is not supported");
     }
-
     /*
      * Serialization is unnecessary for this class. Reject attempts to do so until such time as the Serializable attribute can be dropped.
      */
@@ -140,5 +134,4 @@ public class ProtocolCommandSupport implements Serializable {
     private void writeObject(final ObjectOutputStream ignored) {
         throw new UnsupportedOperationException("Serialization is not supported");
     }
-
 }


(commons-net) 13/15: Internal refactoring for a magic char

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 a93879ea12e3d7eee1a68dd556f9ae33d3463a9a
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 12:03:54 2025 -0500

    Internal refactoring for a magic char
---
 src/main/java/org/apache/commons/net/ftp/FTP.java | 72 ++++++++++++++++-------
 1 file changed, 50 insertions(+), 22 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/ftp/FTP.java b/src/main/java/org/apache/commons/net/ftp/FTP.java
index 4f87dde1..d6a3ec70 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTP.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTP.java
@@ -72,6 +72,11 @@ import org.apache.commons.net.util.NetConstants;
 
 public class FTP extends SocketClient {
 
+    /**
+     * Space character.
+     */
+    private static final char SP = ' ';
+
     /** The default FTP data port (20). */
     public static final int DEFAULT_DATA_PORT = 20;
 
@@ -421,14 +426,13 @@ public class FTP extends SocketClient {
     }
 
     private String buildMessage(final String command, final String args) {
-        final StringBuilder __commandBuffer = new StringBuilder();
-        __commandBuffer.append(command);
+        final StringBuilder builder = new StringBuilder(command);
         if (args != null) {
-            __commandBuffer.append(' ');
-            __commandBuffer.append(args);
+            builder.append(SP);
+            builder.append(args);
         }
-        __commandBuffer.append(NETASCII_EOL);
-        return __commandBuffer.toString();
+        builder.append(NETASCII_EOL);
+        return builder.toString();
     }
 
     /**
@@ -516,26 +520,25 @@ public class FTP extends SocketClient {
      * @since 2.2
      */
     public int eprt(final InetAddress host, final int port) throws IOException {
-        final int num;
-        final StringBuilder info = new StringBuilder();
         // If IPv6, trim the zone index
         String h = host.getHostAddress();
-        num = h.indexOf('%');
+        final int num = h.indexOf('%');
         if (num > 0) {
             h = h.substring(0, num);
         }
-        info.append("|");
+        final StringBuilder builder = new StringBuilder();
+        builder.append("|");
         if (host instanceof Inet4Address) {
-            info.append("1");
+            builder.append("1");
         } else if (host instanceof Inet6Address) {
-            info.append("2");
+            builder.append("2");
         }
-        info.append("|");
-        info.append(h);
-        info.append("|");
-        info.append(port);
-        info.append("|");
-        return sendCommand(FTPCmd.EPRT, info.toString());
+        builder.append("|");
+        builder.append(h);
+        builder.append("|");
+        builder.append(port);
+        builder.append("|");
+        return sendCommand(FTPCmd.EPRT, builder.toString());
     }
 
     /**
@@ -637,7 +640,7 @@ public class FTP extends SocketClient {
                 if (length == REPLY_CODE_LEN + 1) { // expecting some text
                     throw new MalformedServerReplyException("Truncated server reply: '" + line + "'");
                 }
-                if (sep != ' ') {
+                if (sep != SP) {
                     throw new MalformedServerReplyException("Invalid server reply: '" + line + "'");
                 }
             }
@@ -813,7 +816,7 @@ public class FTP extends SocketClient {
      * @see <a href="https://tools.ietf.org/html/draft-somers-ftp-mfxx-04">https://tools.ietf.org/html/draft-somers-ftp-mfxx-04</a>
      **/
     public int mfmt(final String path, final String timeval) throws IOException {
-        return sendCommand(FTPCmd.MFMT, timeval + " " + path);
+        return sendCommand(FTPCmd.MFMT, timeval + SP + path);
     }
 
     /**
@@ -964,6 +967,30 @@ public class FTP extends SocketClient {
         return sendCommand(FTPCmd.NOOP);
     }
 
+    /**
+     * A convenience method to send the FTP OPTS command to the server, receive the reply, and return the reply code.
+     * <p>
+     * FTP request Syntax:
+     * </p>
+     * <pre>{@code
+     * opts             = opts-cmd SP command-name
+     *                         [ SP command-options ] CRLF
+     * opts-cmd         = "opts"
+     * command-name     = <any FTP command which allows option setting>
+     * command-options  = <format specified by individual FTP command>
+     * }</pre>
+     * @param commandName The OPTS command name.
+     * @param commandOptions The OPTS command options.
+     * @return The reply code received from the server.
+     * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
+     *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
+     *                                      independently as itself.
+     * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
+     */
+    public int opts(final String commandName, String commandOptions) throws IOException {
+        return sendCommand(FTPCmd.OPTS, commandName + SP + commandOptions);
+    }
+
     /**
      * A convenience method to send the FTP PASS command to the server, receive the reply, and return the reply code.
      *
@@ -1112,6 +1139,7 @@ public class FTP extends SocketClient {
         return sendCommand(FTPCmd.RNFR, path);
     }
 
+
     /**
      * A convenience method to send the FTP RNTO command to the server, receive the reply, and return the reply code.
      *
@@ -1399,7 +1427,7 @@ public class FTP extends SocketClient {
 
     // The RFC-compliant multiline termination check
     private boolean strictCheck(final String line, final String code) {
-        return !(line.startsWith(code) && line.charAt(REPLY_CODE_LEN) == ' ');
+        return !(line.startsWith(code) && line.charAt(REPLY_CODE_LEN) == SP);
     }
 
     /**
@@ -1457,7 +1485,7 @@ public class FTP extends SocketClient {
     public int type(final int fileType, final int formatOrByteSize) throws IOException {
         final StringBuilder arg = new StringBuilder();
         arg.append(modeCharAt(fileType));
-        arg.append(' ');
+        arg.append(SP);
         if (fileType == LOCAL_FILE_TYPE) {
             arg.append(formatOrByteSize);
         } else {


(commons-net) 04/15: Avoid multiple possible NullPointerException in SocketClient.verifyRemote(Socket)

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 19f5d82b4635abdd24b7ed2bffd6e6a1a90d661d
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 15 16:21:36 2025 -0500

    Avoid multiple possible NullPointerException in
    SocketClient.verifyRemote(Socket)
---
 src/changes/changes.xml                                | 1 +
 src/main/java/org/apache/commons/net/SocketClient.java | 8 +-------
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a4d4468d..d15ae947 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -83,6 +83,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate PrintCommandListeners.PrintCommandListeners().</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate NtpUtils.NtpUtils().</action>
       <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>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">org.apache.commons.net.nntp.Article#getChild().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">org.apache.commons.net.nntp.Article#getNext().</action>
diff --git a/src/main/java/org/apache/commons/net/SocketClient.java b/src/main/java/org/apache/commons/net/SocketClient.java
index a2d340d3..6348e88a 100644
--- a/src/main/java/org/apache/commons/net/SocketClient.java
+++ b/src/main/java/org/apache/commons/net/SocketClient.java
@@ -767,13 +767,7 @@ public abstract class SocketClient {
      * @return True if the remote hosts are the same, false if not.
      */
     public boolean verifyRemote(final Socket socket) {
-        final InetAddress host1;
-        final InetAddress host2;
-
-        host1 = socket.getInetAddress();
-        host2 = getRemoteAddress();
-
-        return host1.equals(host2);
+        return socket != null && Objects.equals(socket.getInetAddress(), getRemoteAddress());
     }
 
     /*


(commons-net) 08/15: Better parameter names

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 def196b2572ab47f7c010838d40ce1b47c7d260c
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 10:52:37 2025 -0500

    Better parameter names
    
    - Javadoc
    - Usage help text
---
 .../commons/net/examples/ftp/FTPClientExample.java |  10 +-
 src/main/java/org/apache/commons/net/ftp/FTP.java  |  78 +++++------
 .../java/org/apache/commons/net/ftp/FTPClient.java | 154 ++++++++++-----------
 .../commons/net/ftp/parser/MLSxEntryParser.java    |   4 +-
 4 files changed, 123 insertions(+), 123 deletions(-)

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 7fbce73b..df17b219 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
@@ -51,18 +51,18 @@ public final class FTPClientExample {
             + "\nDefault behavior is to download a file and use ASCII transfer mode.\n" + "\t-a - use local active mode (default is local passive)\n"
             + "\t-A - anonymous login (omit user and password parameters)\n" + "\t-b - use binary transfer mode\n"
             + "\t-c cmd - issue arbitrary command (remote is used as a parameter if provided) \n"
-            + "\t-d - list directory details using MLSD (remote is used as the pathname if provided)\n" + "\t-e - use EPSV with IPv4 (default false)\n"
+            + "\t-d - list directory details using MLSD (remote is used as the path if provided)\n" + "\t-e - use EPSV with IPv4 (default false)\n"
             + "\t-E - encoding to use for control channel\n" + "\t-f - issue FEAT command (remote and local files are ignored)\n"
             + "\t-h - list hidden files (applies to -l and -n only)\n" + "\t-i - issue SIZE command for a file\n"
-            + "\t-k secs - use keep-alive timer (setControlKeepAliveTimeout)\n" + "\t-l - list files using LIST (remote is used as the pathname if provided)\n"
+            + "\t-k secs - use keep-alive timer (setControlKeepAliveTimeout)\n" + "\t-l - list files using LIST (remote is used as the path if provided)\n"
             + "\t     Files are listed twice: first in raw mode, then as the formatted parsed data.\n"
             + "\t     N.B. if the wrong server-type is used, output may be lost. Use -U or -S as necessary.\n"
             + "\t-L - use lenient future dates (server dates may be up to 1 day into future)\n"
-            + "\t-m - list file details using MDTM (remote is used as the pathname if provided)\n"
-            + "\t-n - list file names using NLST (remote is used as the pathname if provided)\n"
+            + "\t-m - list file details using MDTM (remote is used as the path if provided)\n"
+            + "\t-n - list file names using NLST (remote is used as the path if provided)\n"
             + "\t-p true|false|protocol[,true|false] - use FTPSClient with the specified protocol and/or isImplicit setting\n"
             + "\t-s - store file on server (upload)\n" + "\t-S - systemType set server system type (e.g. Unix VMS WINDOWS)\n"
-            + "\t-t - list file details using MLST (remote is used as the pathname if provided)\n" + "\t-U - save unparseable responses\n"
+            + "\t-t - list file details using MLST (remote is used as the path if provided)\n" + "\t-U - save unparseable responses\n"
             + "\t-w msec - wait time for keep-alive reply (setControlKeepAliveReplyTimeout)\n"
             + "\t-T  all|valid|none - use one of the built-in TrustManager implementations (none = JVM default)\n"
             + "\t-y format - set default date format string\n" + "\t-Y format - set recent date format string\n"
diff --git a/src/main/java/org/apache/commons/net/ftp/FTP.java b/src/main/java/org/apache/commons/net/ftp/FTP.java
index 65a23157..68cdd738 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTP.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTP.java
@@ -409,15 +409,15 @@ public class FTP extends SocketClient {
      * data connection. If you don't need this low level of access, use {@link org.apache.commons.net.ftp.FTPClient} , which will handle all low level details
      * for you.
      *
-     * @param pathname The pathname to use for the file when stored at the remote end of the transfer.
+     * @param path The path to use for the file when stored at the remote end of the transfer.
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int appe(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.APPE, pathname);
+    public int appe(final String path) throws IOException {
+        return sendCommand(FTPCmd.APPE, path);
     }
 
     private String buildMessage(final String command, final String args) {
@@ -468,15 +468,15 @@ public class FTP extends SocketClient {
     /**
      * A convenience method to send the FTP DELE command to the server, receive the reply, and return the reply code.
      *
-     * @param pathname The pathname to delete.
+     * @param path The path to delete.
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int dele(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.DELE, pathname);
+    public int dele(final String path) throws IOException {
+        return sendCommand(FTPCmd.DELE, path);
     }
 
     /**
@@ -799,15 +799,15 @@ public class FTP extends SocketClient {
      * data connection. If you don't need this low level of access, use {@link org.apache.commons.net.ftp.FTPClient} , which will handle all low level details
      * for you.
      *
-     * @param pathname The pathname to list, may be {@code null} in which case the command is sent with no parameters
+     * @param path The path to list, may be {@code null} in which case the command is sent with no parameters
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int list(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.LIST, pathname);
+    public int list(final String path) throws IOException {
+        return sendCommand(FTPCmd.LIST, path);
     }
 
     /**
@@ -825,7 +825,7 @@ public class FTP extends SocketClient {
     /**
      * A convenience method to send the FTP MFMT command to the server, receive the reply, and return the reply code.
      *
-     * @param pathname The pathname for which mtime is to be changed
+     * @param path The path for which mtime is to be changed
      * @param timeval  Timestamp in {@code yyyyMMDDhhmmss} format
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
@@ -835,22 +835,22 @@ public class FTP extends SocketClient {
      * @since 2.2
      * @see <a href="https://tools.ietf.org/html/draft-somers-ftp-mfxx-04">https://tools.ietf.org/html/draft-somers-ftp-mfxx-04</a>
      **/
-    public int mfmt(final String pathname, final String timeval) throws IOException {
-        return sendCommand(FTPCmd.MFMT, timeval + " " + pathname);
+    public int mfmt(final String path, final String timeval) throws IOException {
+        return sendCommand(FTPCmd.MFMT, timeval + " " + path);
     }
 
     /**
      * A convenience method to send the FTP MKD command to the server, receive the reply, and return the reply code.
      *
-     * @param pathname The pathname of the new directory to create.
+     * @param path The path of the new directory to create.
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int mkd(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.MKD, pathname);
+    public int mkd(final String path) throws IOException {
+        return sendCommand(FTPCmd.MKD, path);
     }
 
     /**
@@ -963,15 +963,15 @@ public class FTP extends SocketClient {
      * data connection. If you don't need this low level of access, use {@link org.apache.commons.net.ftp.FTPClient} , which will handle all low level details
      * for you.
      *
-     * @param pathname The pathname to list, may be {@code null} in which case the command is sent with no parameters
+     * @param path The path to list, may be {@code null} in which case the command is sent with no parameters
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int nlst(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.NLST, pathname);
+    public int nlst(final String path) throws IOException {
+        return sendCommand(FTPCmd.NLST, path);
     }
 
     /**
@@ -1099,57 +1099,57 @@ public class FTP extends SocketClient {
      * data connection. If you don't need this low level of access, use {@link org.apache.commons.net.ftp.FTPClient} , which will handle all low level details
      * for you.
      *
-     * @param pathname The pathname of the file to retrieve.
+     * @param path The path of the file to retrieve.
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int retr(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.RETR, pathname);
+    public int retr(final String path) throws IOException {
+        return sendCommand(FTPCmd.RETR, path);
     }
 
     /**
      * A convenience method to send the FTP RMD command to the server, receive the reply, and return the reply code.
      *
-     * @param pathname The pathname of the directory to remove.
+     * @param path The path of the directory to remove.
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int rmd(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.RMD, pathname);
+    public int rmd(final String path) throws IOException {
+        return sendCommand(FTPCmd.RMD, path);
     }
 
     /**
      * A convenience method to send the FTP RNFR command to the server, receive the reply, and return the reply code.
      *
-     * @param pathname The pathname to rename from.
+     * @param path The path to rename from.
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int rnfr(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.RNFR, pathname);
+    public int rnfr(final String path) throws IOException {
+        return sendCommand(FTPCmd.RNFR, path);
     }
 
     /**
      * A convenience method to send the FTP RNTO command to the server, receive the reply, and return the reply code.
      *
-     * @param pathname The pathname to rename to
+     * @param path The path to rename to
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int rnto(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.RNTO, pathname);
+    public int rnto(final String path) throws IOException {
+        return sendCommand(FTPCmd.RNTO, path);
     }
 
     private void send(final String message) throws IOException, FTPConnectionClosedException, SocketException {
@@ -1365,15 +1365,15 @@ public class FTP extends SocketClient {
     /**
      * A convenience method to send the FTP STAT command to the server, receive the reply, and return the reply code.
      *
-     * @param pathname A pathname to list.
+     * @param path A path to list.
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int stat(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.STAT, pathname);
+    public int stat(final String path) throws IOException {
+        return sendCommand(FTPCmd.STAT, path);
     }
 
     /**
@@ -1381,15 +1381,15 @@ public class FTP extends SocketClient {
      * data connection. If you don't need this low level of access, use {@link org.apache.commons.net.ftp.FTPClient} , which will handle all low level details
      * for you.
      *
-     * @param pathname The pathname to use for the file when stored at the remote end of the transfer.
+     * @param path The path to use for the file when stored at the remote end of the transfer.
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int stor(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.STOR, pathname);
+    public int stor(final String path) throws IOException {
+        return sendCommand(FTPCmd.STOR, path);
     }
 
     /**
@@ -1412,15 +1412,15 @@ public class FTP extends SocketClient {
      * data connection. If you don't need this low level of access, use {@link org.apache.commons.net.ftp.FTPClient} , which will handle all low level details
      * for you.
      *
-     * @param pathname The base pathname to use for the file when stored at the remote end of the transfer. Some FTP servers require this.
+     * @param path The base path to use for the file when stored at the remote end of the transfer. Some FTP servers require this.
      * @return The reply code received from the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending the command or receiving the server reply.
      */
-    public int stou(final String pathname) throws IOException {
-        return sendCommand(FTPCmd.STOU, pathname);
+    public int stou(final String path) throws IOException {
+        return sendCommand(FTPCmd.STOU, path);
     }
 
     // The RFC-compliant multiline termination check
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 d96fb299..ca522a5a 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -478,7 +478,7 @@ public class FTPClient extends FTP implements Configurable {
     }
 
     /**
-     * Parse the pathname from a CWD reply.
+     * Parse the path from a CWD reply.
      * <p>
      * According to <a href="http://www.ietf.org/rfc/rfc959.txt">RFC959</a>, it should be the same as for MKD i.e.
      * {@code 257<space>"<directory-name>"[<space>commentary]} where any double-quotes in {@code <directory-name>} are doubled. Unlike MKD, the commentary is
@@ -489,7 +489,7 @@ public class FTPClient extends FTP implements Configurable {
      * </p>
      *
      * @param reply
-     * @return the pathname, without enclosing quotes, or the full string after the reply code and space if the syntax is invalid (i.e. enclosing quotes are
+     * @return the path, without enclosing quotes, or the full string after the reply code and space if the syntax is invalid (i.e. enclosing quotes are
      *         missing or embedded quotes are not doubled)
      */
     // package protected for access by test cases
@@ -1160,15 +1160,15 @@ public class FTPClient extends FTP implements Configurable {
     /**
      * Change the current working directory of the FTP session.
      *
-     * @param pathname The new current working directory.
+     * @param path The new current working directory.
      * @return True if successfully completed, false if not.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
      */
-    public boolean changeWorkingDirectory(final String pathname) throws IOException {
-        return FTPReply.isPositiveCompletion(cwd(pathname));
+    public boolean changeWorkingDirectory(final String path) throws IOException {
+        return FTPReply.isPositiveCompletion(cwd(path));
     }
 
     /**
@@ -1272,15 +1272,15 @@ public class FTPClient extends FTP implements Configurable {
     /**
      * Deletes a file on the FTP server.
      *
-     * @param pathname The pathname of the file to be deleted.
+     * @param path The path of the file to be deleted.
      * @return True if successfully completed, false if not.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
      */
-    public boolean deleteFile(final String pathname) throws IOException {
-        return FTPReply.isPositiveCompletion(dele(pathname));
+    public boolean deleteFile(final String path) throws IOException {
+        return FTPReply.isPositiveCompletion(dele(path));
     }
 
     /**
@@ -1641,7 +1641,7 @@ public class FTPClient extends FTP implements Configurable {
     /**
      * Gets the adjusted string with "-a" added if necessary.
      *
-     * @param pathName the initial pathname
+     * @param pathName the initial path
      * @return the adjusted string with "-a" added if necessary.
      * @since 2.0
      */
@@ -1673,13 +1673,13 @@ public class FTPClient extends FTP implements Configurable {
      * Issue the FTP MDTM command (not supported by all servers) to retrieve the last modification time of a file. The modification string should be in the ISO
      * 3077 form "yyyyMMDDhhmmss(.xxx)?". The timestamp represented should also be in GMT, but not all FTP servers honor this.
      *
-     * @param pathname The file path to query.
+     * @param path The file path to query.
      * @return A string representing the last file modification time in {@code yyyyMMDDhhmmss} format.
      * @throws IOException if an I/O error occurs.
      * @since 2.0
      */
-    public String getModificationTime(final String pathname) throws IOException {
-        if (FTPReply.isPositiveCompletion(mdtm(pathname))) {
+    public String getModificationTime(final String path) throws IOException {
+        if (FTPReply.isPositiveCompletion(mdtm(path))) {
             // skip the return code (e.g. 213) and the space
             return getReplyString(0).substring(4);
         }
@@ -1762,9 +1762,9 @@ public class FTPClient extends FTP implements Configurable {
     }
 
     /**
-     * Issue the FTP SIZE command to the server for a given pathname. This should produce the size of the file.
+     * Issue the FTP SIZE command to the server for a given path. This should produce the size of the file.
      *
-     * @param pathname the file name
+     * @param path the file name
      * @return The size information returned by the server; {@code null} if there was an error
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
@@ -1772,8 +1772,8 @@ 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.
      * @since 3.7
      */
-    public String getSize(final String pathname) throws IOException {
-        if (FTPReply.isPositiveCompletion(size(pathname))) {
+    public String getSize(final String path) throws IOException {
+        if (FTPReply.isPositiveCompletion(size(path))) {
             return getReplyString(0).substring(4); // skip the return code (e.g. 213) and the space
         }
         return null;
@@ -1796,17 +1796,17 @@ public class FTPClient extends FTP implements Configurable {
     }
 
     /**
-     * Issue the FTP STAT command to the server for a given pathname. This should produce a listing of the file or directory.
+     * Issue the FTP STAT command to the server for a given path. This should produce a listing of the file or directory.
      *
-     * @param pathname the file name
+     * @param path the file name
      * @return The status information returned by the server.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @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 getStatus(final String pathname) throws IOException {
-        if (FTPReply.isPositiveCompletion(stat(pathname))) {
+    public String getStatus(final String path) throws IOException {
+        if (FTPReply.isPositiveCompletion(stat(path))) {
             return getReplyString();
         }
         return null;
@@ -2006,8 +2006,8 @@ 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.
      * @see FTPListParseEngine
      */
-    private FTPListParseEngine initiateListParsing(final FTPFileEntryParser parser, final String pathname) throws IOException {
-        final Socket socket = _openDataConnection_(FTPCmd.LIST, getListArguments(pathname));
+    private FTPListParseEngine initiateListParsing(final FTPFileEntryParser parser, final String path) throws IOException {
+        final Socket socket = _openDataConnection_(FTPCmd.LIST, getListArguments(path));
         final FTPListParseEngine engine = new FTPListParseEngine(parser, configuration);
         if (socket == null) {
             return engine;
@@ -2047,7 +2047,7 @@ public class FTPClient extends FTP implements Configurable {
      * }
      * </pre>
      *
-     * @param pathname the starting directory
+     * @param path the starting directory
      * @return A FTPListParseEngine object that holds the raw information and is capable of providing parsed FTPFile objects, one for each file containing
      *         information contained in the given path in the format determined by the {@code parser} parameter. Null will be returned if a data connection
      *         cannot be opened. If the current working directory contains no files, an empty array will be the return.
@@ -2061,8 +2061,8 @@ public class FTPClient extends FTP implements Configurable {
      *                                                                         connected with.
      * @see FTPListParseEngine
      */
-    public FTPListParseEngine initiateListParsing(final String pathname) throws IOException {
-        return initiateListParsing((String) null, pathname);
+    public FTPListParseEngine initiateListParsing(final String path) throws IOException {
+        return initiateListParsing((String) null, path);
     }
 
     /**
@@ -2082,7 +2082,7 @@ public class FTPClient extends FTP implements Configurable {
      *                  server file listing. May be {@code null}, in which case the code checks first the system property {@link #FTP_SYSTEM_TYPE}, and if that
      *                  is not defined the SYST command is used to provide the value. To allow for arbitrary system types, the return from the SYST command is
      *                  used to look up an alias for the type in the {@link #SYSTEM_TYPE_PROPERTIES} properties file if it is available.
-     * @param pathname  the starting directory
+     * @param path  the starting directory
      * @return A FTPListParseEngine object that holds the raw information and is capable of providing parsed FTPFile objects, one for each file containing
      *         information contained in the given path in the format determined by the {@code parser} parameter. Null will be returned if a data connection
      *         cannot be opened. If the current working directory contains no files, an empty array will be the return.
@@ -2100,9 +2100,9 @@ public class FTPClient extends FTP implements Configurable {
      *                                                                         prevent its being loaded.
      * @see FTPListParseEngine
      */
-    public FTPListParseEngine initiateListParsing(final String parserKey, final String pathname) throws IOException {
+    public FTPListParseEngine initiateListParsing(final String parserKey, final String path) throws IOException {
         createParser(parserKey); // create and cache parser
-        return initiateListParsing(entryParser, pathname);
+        return initiateListParsing(entryParser, path);
     }
 
     /**
@@ -2118,12 +2118,12 @@ public class FTPClient extends FTP implements Configurable {
     /**
      * Initiate list parsing for MLSD listings.
      *
-     * @param pathname the path from where to MLSD.
+     * @param path the path from where to MLSD.
      * @return the engine.
      * @throws IOException on error
      */
-    public FTPListParseEngine initiateMListParsing(final String pathname) throws IOException {
-        final Socket socket = _openDataConnection_(FTPCmd.MLSD, pathname);
+    public FTPListParseEngine initiateMListParsing(final String path) throws IOException {
+        final Socket socket = _openDataConnection_(FTPCmd.MLSD, path);
         final FTPListParseEngine engine = new FTPListParseEngine(MLSxEntryParser.getInstance(), configuration);
         if (socket == null) {
             return engine;
@@ -2280,9 +2280,9 @@ public class FTPClient extends FTP implements Configurable {
      * include milliseconds. See {@link #mlistDir()}
      * </p>
      *
-     * @param pathname The file or directory to list. Since the server may or may not expand glob expressions, using them here is not recommended and may well
+     * @param path The file or directory to list. Since the server may or may not expand glob expressions, using them here is not recommended and may well
      *                 cause this method to fail. Also, some servers treat a leading '-' as being an option. To avoid this interpretation, use an absolute
-     *                 pathname or prefix the pathname with ./ (Unix style servers). Some servers may support "--" as meaning end of options, in which case "--
+     *                 path or prefix the path with ./ (Unix style servers). Some servers may support "--" as meaning end of options, in which case "--
      *                 -xyz" should work.
      * @return The list of file information contained in the given path in the format determined by the autodetection mechanism
      * @throws FTPConnectionClosedException                                    If the FTP server prematurely closes the connection as a result of the client
@@ -2300,21 +2300,21 @@ public class FTPClient extends FTP implements Configurable {
      * @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory
      * @see org.apache.commons.net.ftp.FTPFileEntryParser
      */
-    public FTPFile[] listFiles(final String pathname) throws IOException {
-        return initiateListParsing((String) null, pathname).getFiles();
+    public FTPFile[] listFiles(final String path) throws IOException {
+        return initiateListParsing((String) null, path).getFiles();
     }
 
     /**
      * Version of {@link #listFiles(String)} which allows a filter to be provided. For example: {@code listFiles("site", FTPFileFilters.DIRECTORY);}
      *
-     * @param pathname the initial path, may be null
+     * @param path the initial path, may be null
      * @param filter   the filter, non-null
      * @return the array of FTPFile entries.
      * @throws IOException on error
      * @since 2.2
      */
-    public FTPFile[] listFiles(final String pathname, final FTPFileFilter filter) throws IOException {
-        return initiateListParsing((String) null, pathname).getFiles(filter);
+    public FTPFile[] listFiles(final String path, final FTPFileFilter filter) throws IOException {
+        return initiateListParsing((String) null, path).getFiles(filter);
     }
 
     /**
@@ -2362,11 +2362,11 @@ public class FTPClient extends FTP implements Configurable {
 
     /**
      * Obtain a list of file names in a directory (or just the name of a given file, which is not particularly useful). This information is obtained through the
-     * NLST command. If the given pathname is a directory and contains no files, a zero length array is returned only if the FTP server returned a positive
+     * NLST command. If the given path is a directory and contains no files, a zero length array is returned only if the FTP server returned a positive
      * completion code, otherwise null is returned (the FTP server returned a 550 error No files found.). If the directory is not empty, an array of file names
-     * in the directory is returned. If the pathname corresponds to a file, only that file will be listed. The server may or may not expand glob expressions.
+     * in the directory is returned. If the path corresponds to a file, only that file will be listed. The server may or may not expand glob expressions.
      *
-     * @param pathname The file or directory to list. Warning: the server may treat a leading '-' as an option introducer. If so, try using an absolute path, or
+     * @param path The file or directory to list. Warning: the server may treat a leading '-' as an option introducer. If so, try using an absolute path, or
      *                 prefix the path with ./ (Unix style servers). Some servers may support "--" as meaning end of options, in which case "-- -xyz" should
      *                 work.
      * @return The list of file names contained in the given path. null if the list could not be obtained. If there are no file names in the directory, a
@@ -2376,9 +2376,9 @@ public class FTPClient extends FTP implements Configurable {
      *                                      independently as itself.
      * @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 pathname) throws IOException {
+    public String[] listNames(final String path) throws IOException {
         final ArrayList<String> results = new ArrayList<>();
-        try (Socket socket = _openDataConnection_(FTPCmd.NLST, getListArguments(pathname))) {
+        try (Socket socket = _openDataConnection_(FTPCmd.NLST, getListArguments(path))) {
             if (socket == null) {
                 return null;
             }
@@ -2466,31 +2466,31 @@ public class FTPClient extends FTP implements Configurable {
     }
 
     /**
-     * Creates a new subdirectory on the FTP server in the current directory (if a relative pathname is given) or where specified (if an absolute pathname is
+     * Creates a new subdirectory on the FTP server in the current directory (if a relative path is given) or where specified (if an absolute path is
      * given).
      *
-     * @param pathname The pathname of the directory to create.
+     * @param path The path of the directory to create.
      * @return True if successfully completed, false if not.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
      */
-    public boolean makeDirectory(final String pathname) throws IOException {
-        return FTPReply.isPositiveCompletion(mkd(pathname));
+    public boolean makeDirectory(final String path) throws IOException {
+        return FTPReply.isPositiveCompletion(mkd(path));
     }
 
     /**
      * Issue the FTP MDTM command (not supported by all servers) to retrieve the last modification time of a file. The modification string should be in the ISO
      * 3077 form "yyyyMMDDhhmmss(.xxx)?". The timestamp represented should also be in GMT, but not all FTP servers honor this.
      *
-     * @param pathname The file path to query.
+     * @param path The file path to query.
      * @return A Calendar representing the last file modification time, may be {@code null}. The Calendar timestamp will be null if a parse error occurs.
      * @throws IOException if an I/O error occurs.
      * @since 3.8.0
      */
-    public Calendar mdtmCalendar(final String pathname) throws IOException {
-        final String modificationTime = getModificationTime(pathname);
+    public Calendar mdtmCalendar(final String path) throws IOException {
+        final String modificationTime = getModificationTime(path);
         if (modificationTime != null) {
             return MLSxEntryParser.parseGMTdateTime(modificationTime);
         }
@@ -2501,16 +2501,16 @@ public class FTPClient extends FTP implements Configurable {
      * Issue the FTP MDTM command (not supported by all servers) to retrieve the last modification time of a file. The modification string should be in the ISO
      * 3077 form "yyyyMMDDhhmmss(.xxx)?". The timestamp represented should also be in GMT, but not all FTP servers honor this.
      *
-     * @param pathname The file path to query.
+     * @param path The file path to query.
      * @return A FTPFile representing the last file modification time, may be {@code null}. The FTPFile timestamp will be null if a parse error occurs.
      * @throws IOException if an I/O error occurs.
      * @since 3.4
      */
-    public FTPFile mdtmFile(final String pathname) throws IOException {
-        final String modificationTime = getModificationTime(pathname);
+    public FTPFile mdtmFile(final String path) throws IOException {
+        final String modificationTime = getModificationTime(path);
         if (modificationTime != null) {
             final FTPFile file = new FTPFile();
-            file.setName(pathname);
+            file.setName(path);
             file.setRawListing(modificationTime);
             file.setTimestamp(MLSxEntryParser.parseGMTdateTime(modificationTime));
             return file;
@@ -2522,13 +2522,13 @@ public class FTPClient extends FTP implements Configurable {
      * Issue the FTP MDTM command (not supported by all servers) to retrieve the last modification time of a file. The modification string should be in the ISO
      * 3077 form "yyyyMMDDhhmmss(.xxx)?". The timestamp represented should also be in GMT, but not all FTP servers honor this.
      *
-     * @param pathname The file path to query.
+     * @param path The file path to query.
      * @return An Instant representing the last file modification time, may be {@code null}. The Instant timestamp will be null if a parse error occurs.
      * @throws IOException if an I/O error occurs.
      * @since 3.9.0
      */
-    public Instant mdtmInstant(final String pathname) throws IOException {
-        final String modificationTime = getModificationTime(pathname);
+    public Instant mdtmInstant(final String path) throws IOException {
+        final String modificationTime = getModificationTime(path);
         if (modificationTime != null) {
             return MLSxEntryParser.parseGmtInstant(modificationTime);
         }
@@ -2570,38 +2570,38 @@ public class FTPClient extends FTP implements Configurable {
     /**
      * Generate a directory listing using the MLSD command.
      *
-     * @param pathname the directory name, may be {@code null}
+     * @param path the directory name, may be {@code null}
      * @return the array of file entries
      * @throws IOException on error
      * @since 3.0
      */
-    public FTPFile[] mlistDir(final String pathname) throws IOException {
-        return initiateMListParsing(pathname).getFiles();
+    public FTPFile[] mlistDir(final String path) throws IOException {
+        return initiateMListParsing(path).getFiles();
     }
 
     /**
      * Generate a directory listing using the MLSD command.
      *
-     * @param pathname the directory name, may be {@code null}
+     * @param path the directory name, may be {@code null}
      * @param filter   the filter to apply to the responses
      * @return the array of file entries
      * @throws IOException on error
      * @since 3.0
      */
-    public FTPFile[] mlistDir(final String pathname, final FTPFileFilter filter) throws IOException {
-        return initiateMListParsing(pathname).getFiles(filter);
+    public FTPFile[] mlistDir(final String path, final FTPFileFilter filter) throws IOException {
+        return initiateMListParsing(path).getFiles(filter);
     }
 
     /**
      * Gets file details using the MLST command
      *
-     * @param pathname the file or directory to list, may be {@code null}
+     * @param path the file or directory to list, may be {@code null}
      * @return the file details, may be {@code null}
      * @throws IOException on error
      * @since 3.0
      */
-    public FTPFile mlistFile(final String pathname) throws IOException {
-        final boolean success = FTPReply.isPositiveCompletion(sendCommand(FTPCmd.MLST, pathname));
+    public FTPFile mlistFile(final String path) throws IOException {
+        final boolean success = FTPReply.isPositiveCompletion(sendCommand(FTPCmd.MLST, path));
         if (success) {
             String reply = getReplyString(1);
             // some FTP server reply not contains space before fact(s)
@@ -2623,9 +2623,9 @@ public class FTPClient extends FTP implements Configurable {
     }
 
     /**
-     * Returns the pathname of the current working directory.
+     * Returns the path of the current working directory.
      *
-     * @return The pathname of the current working directory. If it cannot be obtained, returns null.
+     * @return The path of the current working directory. If it cannot be obtained, returns null.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
@@ -2750,15 +2750,15 @@ public class FTPClient extends FTP implements Configurable {
     /**
      * Removes a directory on the FTP server (if empty).
      *
-     * @param pathname The pathname of the directory to remove.
+     * @param path The path of the directory to remove.
      * @return True if successfully completed, false if not.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
      */
-    public boolean removeDirectory(final String pathname) throws IOException {
-        return FTPReply.isPositiveCompletion(rmd(pathname));
+    public boolean removeDirectory(final String path) throws IOException {
+        return FTPReply.isPositiveCompletion(rmd(path));
     }
 
     /**
@@ -3130,15 +3130,15 @@ public class FTPClient extends FTP implements Configurable {
      * An FTP server would indicate its support of this feature by including "MFMT" in its response to the FEAT command, which may be retrieved by
      * FTPClient.features()
      *
-     * @param pathname The file path for which last modified time is to be changed.
+     * @param path The file path for which last modified time is to be changed.
      * @param timeval  The timestamp to set to, in {@code yyyyMMDDhhmmss} format.
      * @return true if successfully set, false if not
      * @throws IOException if an I/O error occurs.
      * @since 2.2
      * @see <a href="https://tools.ietf.org/html/draft-somers-ftp-mfxx-04">https://tools.ietf.org/html/draft-somers-ftp-mfxx-04</a>
      */
-    public boolean setModificationTime(final String pathname, final String timeval) throws IOException {
-        return FTPReply.isPositiveCompletion(mfmt(pathname, timeval));
+    public boolean setModificationTime(final String path, final String timeval) throws IOException {
+        return FTPReply.isPositiveCompletion(mfmt(path, timeval));
     }
 
     /**
@@ -3410,15 +3410,15 @@ public class FTPClient extends FTP implements Configurable {
     /**
      * Issue the FTP SMNT command.
      *
-     * @param pathname The pathname to mount.
+     * @param path The path to mount.
      * @return True if successfully completed, false if not.
      * @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
      *                                      causing the server to send FTP reply code 421. This exception may be caught either as an IOException or
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
      */
-    public boolean structureMount(final String pathname) throws IOException {
-        return FTPReply.isPositiveCompletion(smnt(pathname));
+    public boolean structureMount(final String path) throws IOException {
+        return FTPReply.isPositiveCompletion(smnt(path));
     }
 
     private Socket wrapOnDeflate(final Socket plainSocket) {
diff --git a/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java b/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
index 269fa02d..feeb87b0 100644
--- a/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
+++ b/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
@@ -37,7 +37,7 @@ import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
  * </p>
  *
  * <pre>
- * entry            = [ facts ] SP pathname
+ * entry            = [ facts ] SP path
  * facts            = 1*( fact ";" )
  * fact             = factname "=" value
  * factname         = "Size" / "Modify" / "Create" /
@@ -208,7 +208,7 @@ public class MLSxEntryParser extends FTPFileEntryParserImpl {
                 file.setName(entry.substring(1));
                 return file;
             }
-            return null; // Invalid - no pathname
+            return null; // Invalid - no path
 
         }
         final String[] parts = entry.split(" ", 2); // Path may contain space


(commons-net) 06/15: 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 7046ea5f9a411088f94ef593c92ea3386e4bb641
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 09:53:13 2025 -0500

    Javadoc
    
    - Remove old private comment
    - Less vertical whitespace
---
 src/main/java/org/apache/commons/net/ftp/FTPClient.java   |  3 ---
 .../org/apache/commons/net/io/CopyStreamListener.java     | 15 +++++++--------
 2 files changed, 7 insertions(+), 11 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 7e0763d0..d96fb299 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -267,7 +267,6 @@ import org.apache.commons.net.util.NetConstants;
  */
 public class FTPClient extends FTP implements Configurable {
 
-    // @since 3.0
     private static final class CSL implements CopyStreamListener {
 
         private final FTPClient parent;
@@ -910,11 +909,9 @@ public class FTPClient extends FTP implements Configurable {
                 } else {
                     input = getBufferedInputStream(socket.getInputStream());
                 }
-
                 if (DurationUtils.isPositive(controlKeepAliveTimeout)) {
                     csl = new CSL(this, controlKeepAliveTimeout, controlKeepAliveReplyTimeout);
                 }
-
                 // Treat everything else as binary for now
                 Util.copyStream(input, local, getBufferSize(), CopyStreamEvent.UNKNOWN_STREAM_SIZE, mergeListeners(csl), false);
             } finally {
diff --git a/src/main/java/org/apache/commons/net/io/CopyStreamListener.java b/src/main/java/org/apache/commons/net/io/CopyStreamListener.java
index b139a501..8dd9e1c4 100644
--- a/src/main/java/org/apache/commons/net/io/CopyStreamListener.java
+++ b/src/main/java/org/apache/commons/net/io/CopyStreamListener.java
@@ -14,17 +14,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.commons.net.io;
 
 import java.util.EventListener;
 
 /**
- * The CopyStreamListener class can accept CopyStreamEvents to keep track of the progress of a stream copying operation. However, it is currently not used that
- * way within NetComponents for performance reasons. Rather the bytesTransferred(long, int) method is called directly rather than passing an event to
- * bytesTransferred(CopyStreamEvent), saving the creation of a CopyStreamEvent instance. Also, the only place where CopyStreamListener is currently used within
- * NetComponents is in the static methods of the uninstantiable org.apache.commons.io.Util class, which would preclude the use of addCopyStreamListener and
- * removeCopyStreamListener methods. However, future additions may use the JavaBean event model, which is why the hooks have been included from the beginning.
+ * Accepts {@link CopyStreamEvent}s to track the progress of a stream copying operation. However, it is currently not used that way within Net for performance
+ * reasons. Rather, the bytesTransferred(long, int) method is called directly rather than passing an event to bytesTransferred(CopyStreamEvent), saving the
+ * creation of a CopyStreamEvent instance. Also, the only place where CopyStreamListener is currently used within Net is in the static methods of the
+ * uninstantiable org.apache.commons.io.Util class, which would preclude the use of addCopyStreamListener and removeCopyStreamListener methods. However, future
+ * additions may use the JavaBean event model, which is why the hooks have been included from the beginning.
  *
  *
  * @see CopyStreamEvent
@@ -33,8 +32,8 @@ import java.util.EventListener;
  */
 public interface CopyStreamListener extends EventListener {
     /**
-     * This method is invoked by a CopyStreamEvent source after copying a block of bytes from a stream. The CopyStreamEvent will contain the total number of
-     * bytes transferred so far and the number of bytes transferred in the last write.
+     * Accepts a source event after copying a block of bytes from a stream. The CopyStreamEvent will contain the total number of bytes transferred so far and
+     * the number of bytes transferred in the last write.
      *
      * @param event The CopyStreamEvent fired by the copying of a block of bytes.
      */


(commons-net) 09/15: 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 c1a0ef0abc14fceb0cbb9df7a8cc382ba5c198f3
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 11:01:14 2025 -0500

    Javadoc
---
 .../java/org/apache/commons/net/ftp/FTPClientConfig.java   | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java b/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
index 7c6696f0..e460cd77 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
@@ -27,7 +27,7 @@ import java.util.TreeMap;
 /**
  * <p>
  * This class implements an alternate means of configuring the {@link org.apache.commons.net.ftp.FTPClient FTPClient} object and also subordinate objects which
- * it uses. Any class implementing the {@link org.apache.commons.net.ftp.Configurable Configurable } interface can be configured by this object.
+ * it uses. Any class implementing the {@link org.apache.commons.net.ftp.Configurable Configurable} interface can be configured by this object.
  * </p>
  * <p>
  * In particular this class was designed primarily to support configuration of FTP servers which express file timestamps in formats and languages other than
@@ -46,7 +46,7 @@ import java.util.TreeMap;
  * </ul>
  * <p>
  * Unpaged (whole list) access on a Unix server that uses French month names but uses the "standard" {@code MMM d yyyy} date formatting
- *
+ * </p>
  * <pre>
  * FTPClient f = FTPClient();
  * FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
@@ -58,7 +58,7 @@ import java.util.TreeMap;
  * </pre>
  * <p>
  * Paged access on a Unix server that uses Danish month names and "European" date formatting in Denmark's time zone, when you are in some other time zone.
- *
+ * </p>
  * <pre>
  * FTPClient f = FTPClient();
  * FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
@@ -80,7 +80,7 @@ import java.util.TreeMap;
  * <p>
  * Unpaged (whole list) access on a VMS server that uses month names in a language not {@link #getSupportedLanguageCodes() supported} by the system. but uses
  * the "standard" {@code MMM d yyyy} date formatting
- *
+ * </p>
  * <pre>
  * FTPClient f = FTPClient();
  * FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_VMS);
@@ -93,7 +93,7 @@ import java.util.TreeMap;
  * <p>
  * Unpaged (whole list) access on a Windows-NT server in a different time zone. (Note, since the NT Format uses numeric date formatting, language issues are
  * irrelevant here).
- *
+ * </p>
  * <pre>
  * FTPClient f = FTPClient();
  * FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);
@@ -103,9 +103,9 @@ import java.util.TreeMap;
  * f.login(user, password);
  * FTPFile[] files = listFiles(directory);
  * </pre>
- *
+ * <p>
  * Unpaged (whole list) access on a Windows-NT server in a different time zone but which has been configured to use a unix-style listing format.
- *
+ * </p>
  * <pre>
  * FTPClient f = FTPClient();
  * FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);


(commons-net) 01/15: Add FTPCmd.OPTS

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 f80f96395e88099ba6651bc4ebf1e8ee579cf2a9
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 15 16:00:15 2025 -0500

    Add FTPCmd.OPTS
---
 src/changes/changes.xml                              | 3 ++-
 src/main/java/org/apache/commons/net/ftp/FTPCmd.java | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5ca64e85..a4d4468d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -88,7 +88,8 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="add" dev="ggregory" due-to="Gary Gregory">org.apache.commons.net.nntp.Article#getNext().</action>
       <action type="add" dev="ggregory" due-to="Lixiongyou, Gary Gregory">Add private SubnetAddressStringIterable and private SubnetAddressStringIterator to implement SubnetInfo.iterableAddressStrings() and SubnetInfo.streamAddressStrings() #298.</action> 
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add SubnetInfo.iterableAddressStrings().</action> 
-      <action type="add" dev="ggregory" due-to="Gary Gregory">Add SubnetInfo.streamAddressStrings().</action> 
+      <action type="add" dev="ggregory" due-to="Gary Gregory">Add SubnetInfo.streamAddressStrings().</action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">Add FTPCmd.OPTS.</action>
       <!-- UPDATE -->
       <action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 70 to 81 #261, #278, #280, #285, #298, #293, #300.</action>
       <action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.17.0 #268, #273, #281.</action>
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPCmd.java b/src/main/java/org/apache/commons/net/ftp/FTPCmd.java
index 37667b50..5e31ca30 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPCmd.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPCmd.java
@@ -84,6 +84,13 @@ public enum FTPCmd {
     /** FTP command NOOP. */
     NOOP,
 
+    /**
+     * FTP command <a href="https://datatracker.ietf.org/doc/html/rfc2389#section-4">OPTS</a>.
+     *
+     * @since 3.12.0
+     */
+    OPTS,
+
     /** FTP command PASS. */
     PASS,
 


(commons-net) 05/15: 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 4b5ac366f0d7dc341bc244b9cc4dae0b4317b194
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 09:47:31 2025 -0500

    Reuse IOUtils
    
    Javadoc
---
 .../java/org/apache/commons/net/SocketClient.java  | 22 +++++++++++++++++++++
 .../org/apache/commons/net/bsd/RCommandClient.java |  9 ++++-----
 .../org/apache/commons/net/bsd/RExecClient.java    |  9 ++++-----
 .../commons/net/examples/ftp/TFTPExample.java      | 11 ++++++++---
 .../java/org/apache/commons/net/ftp/FTPClient.java | 23 +++++++++++-----------
 .../org/apache/commons/net/ftp/FTPSClient.java     | 20 +++++++------------
 src/main/java/org/apache/commons/net/io/Util.java  | 21 +++++++-------------
 .../org/apache/commons/net/nntp/ReplyIterator.java |  8 ++++----
 .../apache/commons/net/util/KeyManagerUtils.java   |  4 ++--
 9 files changed, 70 insertions(+), 57 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/SocketClient.java b/src/main/java/org/apache/commons/net/SocketClient.java
index 6348e88a..31d6b873 100644
--- a/src/main/java/org/apache/commons/net/SocketClient.java
+++ b/src/main/java/org/apache/commons/net/SocketClient.java
@@ -60,6 +60,28 @@ public abstract class SocketClient {
     /** The socket's connect timeout (0 = infinite timeout) */
     private static final int DEFAULT_CONNECT_TIMEOUT = 60000;
 
+    /**
+     * Gets the IP address string of the given Socket in textual presentation.
+     *
+     * @param socket the socket to query.
+     * @return  the raw IP address in a string format.
+     * @since 3.12.0
+     */
+    protected static String getHostAddress(final Socket socket) {
+        return getHostAddress(socket.getInetAddress());
+    }
+
+    /**
+     * Gets the IP address string of the given InetAddress in textual presentation.
+     *
+     * @param inetAddress Internet Protocol (IP) address to query.
+     * @return  the raw IP address in a string format.
+     * @since 3.12.0
+     */
+    protected static String getHostAddress(final InetAddress inetAddress) {
+        return inetAddress != null ? inetAddress.getHostAddress() : null;
+    }
+
     /**
      * A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and the firing of ProtocolCommandEvents.
      */
diff --git a/src/main/java/org/apache/commons/net/bsd/RCommandClient.java b/src/main/java/org/apache/commons/net/bsd/RCommandClient.java
index af4bace4..52022315 100644
--- a/src/main/java/org/apache/commons/net/bsd/RCommandClient.java
+++ b/src/main/java/org/apache/commons/net/bsd/RCommandClient.java
@@ -27,6 +27,7 @@ import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.nio.charset.StandardCharsets;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.net.io.SocketInputStream;
 
 /**
@@ -220,19 +221,17 @@ public class RCommandClient extends RExecClient {
     @Override
     InputStream createErrorStream() throws IOException {
         final Socket socket;
-
         try (ServerSocket server = createServer()) {
             _output_.write(Integer.toString(server.getLocalPort()).getBytes(StandardCharsets.UTF_8));
             _output_.write(NULL_CHAR);
             _output_.flush();
             socket = server.accept();
         }
-
         if (isRemoteVerificationEnabled() && !verifyRemote(socket)) {
-            socket.close();
-            throw new IOException("Security violation: unexpected connection attempt by " + socket.getInetAddress().getHostAddress());
+            final String hostAddress = getHostAddress(socket);
+            IOUtils.closeQuietly(socket);
+            throw new IOException("Security violation: unexpected connection attempt by " + hostAddress);
         }
-
         return new SocketInputStream(socket, socket.getInputStream());
     }
 
diff --git a/src/main/java/org/apache/commons/net/bsd/RExecClient.java b/src/main/java/org/apache/commons/net/bsd/RExecClient.java
index fc469eee..a121bff7 100644
--- a/src/main/java/org/apache/commons/net/bsd/RExecClient.java
+++ b/src/main/java/org/apache/commons/net/bsd/RExecClient.java
@@ -24,6 +24,7 @@ import java.net.ServerSocket;
 import java.net.Socket;
 import java.nio.charset.StandardCharsets;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.net.SocketClient;
 import org.apache.commons.net.io.SocketInputStream;
 import org.apache.commons.net.util.NetConstants;
@@ -82,19 +83,17 @@ public class RExecClient extends SocketClient {
     // limitations of rcmd and rlogin
     InputStream createErrorStream() throws IOException {
         final Socket socket;
-
         try (ServerSocket server = _serverSocketFactory_.createServerSocket(0, 1, getLocalAddress())) {
             _output_.write(Integer.toString(server.getLocalPort()).getBytes(StandardCharsets.UTF_8)); // $NON-NLS-1$
             _output_.write(NULL_CHAR);
             _output_.flush();
             socket = server.accept();
         }
-
         if (remoteVerificationEnabled && !verifyRemote(socket)) {
-            socket.close();
-            throw new IOException("Security violation: unexpected connection attempt by " + socket.getInetAddress().getHostAddress());
+            final String hostAddress = getHostAddress(socket);
+            IOUtils.closeQuietly(socket);
+            throw new IOException("Security violation: unexpected connection attempt by " + hostAddress);
         }
-
         return new SocketInputStream(socket, socket.getInputStream());
     }
 
diff --git a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
index 76feaf9d..0e90f180 100644
--- a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
+++ b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
@@ -26,6 +26,7 @@ import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.time.Duration;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.net.tftp.TFTP;
 import org.apache.commons.net.tftp.TFTPClient;
 import org.apache.commons.net.tftp.TFTPPacket;
@@ -50,9 +51,7 @@ public final class TFTPExample {
         boolean closed;
         tftp.close();
         try {
-            if (output != null) {
-                output.close();
-            }
+            IOUtils.close(output);
             closed = true;
         } catch (final IOException e) {
             closed = false;
@@ -62,6 +61,12 @@ public final class TFTPExample {
         return closed;
     }
 
+    /**
+     * Runs this application.
+     *
+     * @param args command line arguments.
+     * @throws IOException if a network or I/O error occurs.
+     */
     public static void main(final String[] args) throws IOException {
         boolean receiveFile = true, closed;
         int transferMode = TFTP.BINARY_MODE, argc;
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 6931e8e8..7e0763d0 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -47,6 +47,7 @@ import java.util.Random;
 import java.util.Set;
 import java.util.regex.Matcher;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.net.MalformedServerReplyException;
 import org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory;
 import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
@@ -682,12 +683,12 @@ public class FTPClient extends FTP implements Configurable {
      * {@link #setRestartOffset(long)}, a REST command is issued to the server with the offset as an argument before establishing the data connection. Active
      * mode connections also cause a local PORT command to be issued.
      *
-     * @deprecated (3.3) Use {@link #_openDataConnection_(FTPCmd, String)} instead
      * @param command The int representation of the FTP command to send.
      * @param arg     The arguments to the FTP command. If this parameter is set to null, then the command is sent with no argument.
      * @return A Socket corresponding to the established data connection. Null is returned if an FTP protocol error is reported at any point during the
      *         establishment and initialization of the connection.
      * @throws IOException If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
+     * @deprecated (3.3) Use {@link #_openDataConnection_(FTPCmd, String)} instead
      */
     @Deprecated
     protected Socket _openDataConnection_(final int command, final String arg) throws IOException {
@@ -807,10 +808,10 @@ public class FTPClient extends FTP implements Configurable {
         }
         if (remoteVerificationEnabled && !verifyRemote(socket)) {
             // Grab the host before we close the socket to avoid NET-663
-            final InetAddress socketHost = socket.getInetAddress();
-            socket.close();
-            throw new IOException(
-                    "Host attempting data connection " + socketHost.getHostAddress() + " is not same as server " + getRemoteAddress().getHostAddress());
+            final String socketHostAddress = getHostAddress(socket);
+            final String remoteHostAddress = getHostAddress(_socket_);
+            IOUtils.closeQuietly(socket);
+            throw new IOException("Host attempting data connection " + socketHostAddress + " is not same as server " + remoteHostAddress);
         }
         return socket;
     }
@@ -917,12 +918,12 @@ public class FTPClient extends FTP implements Configurable {
                 // Treat everything else as binary for now
                 Util.copyStream(input, local, getBufferSize(), CopyStreamEvent.UNKNOWN_STREAM_SIZE, mergeListeners(csl), false);
             } finally {
-                Util.closeQuietly(input);
+                IOUtils.closeQuietly(input);
             }
             // Get the transfer response
             return completePendingCommand();
         } finally {
-            Util.closeQuietly(socket);
+            IOUtils.closeQuietly(socket);
             if (csl != null) {
                 cslDebug = csl.cleanUp(); // fetch any outstanding keepalive replies
             }
@@ -992,8 +993,8 @@ public class FTPClient extends FTP implements Configurable {
             // Get the transfer response
             return completePendingCommand();
         } catch (final IOException e) {
-            Util.closeQuietly(output); // ignore close errors here
-            Util.closeQuietly(socket); // ignore close errors here
+            IOUtils.closeQuietly(output); // ignore close errors here
+            IOUtils.closeQuietly(socket); // ignore close errors here
             throw e;
         } finally {
             if (csl != null) {
@@ -2017,7 +2018,7 @@ public class FTPClient extends FTP implements Configurable {
         try {
             engine.readServerList(socket.getInputStream(), getControlEncoding());
         } finally {
-            Util.closeQuietly(socket);
+            IOUtils.closeQuietly(socket);
         }
         completePendingCommand();
         return engine;
@@ -2133,7 +2134,7 @@ public class FTPClient extends FTP implements Configurable {
         try {
             engine.readServerList(socket.getInputStream(), getControlEncoding());
         } finally {
-            Util.closeQuietly(socket);
+            IOUtils.closeQuietly(socket);
             completePendingCommand();
         }
         return engine;
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
index 806e1c0e..d51f9ae9 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
@@ -38,6 +38,7 @@ import javax.net.ssl.SSLSocket;
 import javax.net.ssl.SSLSocketFactory;
 import javax.net.ssl.TrustManager;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.net.util.SSLContextUtils;
 import org.apache.commons.net.util.SSLSocketUtils;
 import org.apache.commons.net.util.TrustManagerUtils;
@@ -330,19 +331,14 @@ public class FTPSClient extends FTPClient {
     }
 
     /**
-     * Close open sockets.
+     * Closes sockets.
      *
-     * @param socket    main socket for proxy if enabled
-     * @param sslSocket ssl socket
-     * @throws IOException closing sockets is not successful
+     * @param socket    main socket for proxy if enabled.
+     * @param sslSocket SSL socket.
+     * @throws IOException closing sockets is not successful.
      */
     private void closeSockets(final Socket socket, final Socket sslSocket) throws IOException {
-        if (socket != null) {
-            socket.close();
-        }
-        if (sslSocket != null) {
-            sslSocket.close();
-        }
+        IOUtils.close(socket, sslSocket);
     }
 
     /**
@@ -372,9 +368,7 @@ public class FTPSClient extends FTPClient {
     @Override
     public void disconnect() throws IOException {
         super.disconnect();
-        if (plainSocket != null) {
-            plainSocket.close();
-        }
+        IOUtils.close(plainSocket);
         setSocketFactory(null);
         setServerSocketFactory(null);
     }
diff --git a/src/main/java/org/apache/commons/net/io/Util.java b/src/main/java/org/apache/commons/net/io/Util.java
index fd53a52f..abdb2520 100644
--- a/src/main/java/org/apache/commons/net/io/Util.java
+++ b/src/main/java/org/apache/commons/net/io/Util.java
@@ -29,6 +29,7 @@ import java.io.Writer;
 import java.net.Socket;
 import java.nio.charset.Charset;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.net.util.NetConstants;
 
 /**
@@ -53,15 +54,11 @@ public final class Util {
      *
      * @param closeable the object to close, may be {@code null}
      * @since 3.0
+     * @deprecated Use {@link IOUtils#closeQuietly(Closeable)}.
      */
+    @Deprecated
     public static void closeQuietly(final Closeable closeable) {
-        if (closeable != null) {
-            try {
-                closeable.close();
-            } catch (final IOException e) {
-                // Ignored
-            }
-        }
+        IOUtils.closeQuietly(closeable);
     }
 
     /**
@@ -69,15 +66,11 @@ public final class Util {
      *
      * @param socket the socket to close, may be {@code null}
      * @since 3.0
+     * @deprecated Use {@link IOUtils#closeQuietly(Socket)}.
      */
+    @Deprecated
     public static void closeQuietly(final Socket socket) {
-        if (socket != null) {
-            try {
-                socket.close();
-            } catch (final IOException e) {
-                // Ignored
-            }
-        }
+        IOUtils.closeQuietly(socket);
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/net/nntp/ReplyIterator.java b/src/main/java/org/apache/commons/net/nntp/ReplyIterator.java
index fcf814d4..67018e5b 100644
--- a/src/main/java/org/apache/commons/net/nntp/ReplyIterator.java
+++ b/src/main/java/org/apache/commons/net/nntp/ReplyIterator.java
@@ -22,8 +22,8 @@ import java.io.IOException;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.net.io.DotTerminatedMessageReader;
-import org.apache.commons.net.io.Util;
 
 /**
  * Wraps a {@link BufferedReader} and returns an {@code Iterable<String>} which returns the individual lines from the reader.
@@ -52,7 +52,7 @@ final class ReplyIterator implements Iterator<String>, Iterable<String> {
         reader = addDotReader ? new DotTerminatedMessageReader(_reader) : _reader;
         line = reader.readLine(); // prime the iterator
         if (line == null) {
-            Util.closeQuietly(reader);
+            IOUtils.closeQuietly(reader);
         }
     }
 
@@ -81,11 +81,11 @@ final class ReplyIterator implements Iterator<String>, Iterable<String> {
         try {
             line = reader.readLine(); // save next line
             if (line == null) {
-                Util.closeQuietly(reader);
+                IOUtils.closeQuietly(reader);
             }
         } catch (final IOException ex) {
             savedException = ex; // if it fails, save the exception, as it does not apply to this call
-            Util.closeQuietly(reader);
+            IOUtils.closeQuietly(reader);
         }
         return prev;
     }
diff --git a/src/main/java/org/apache/commons/net/util/KeyManagerUtils.java b/src/main/java/org/apache/commons/net/util/KeyManagerUtils.java
index 9bddd96c..2a71cb75 100644
--- a/src/main/java/org/apache/commons/net/util/KeyManagerUtils.java
+++ b/src/main/java/org/apache/commons/net/util/KeyManagerUtils.java
@@ -34,7 +34,7 @@ import java.util.Enumeration;
 import javax.net.ssl.KeyManager;
 import javax.net.ssl.X509ExtendedKeyManager;
 
-import org.apache.commons.net.io.Util;
+import org.apache.commons.io.IOUtils;
 
 /**
  * General KeyManager utilities
@@ -219,7 +219,7 @@ public final class KeyManagerUtils {
             stream = new FileInputStream(storePath);
             ks.load(stream, storePass.toCharArray());
         } finally {
-            Util.closeQuietly(stream);
+            IOUtils.closeQuietly(stream);
         }
         return ks;
     }


(commons-net) 12/15: PrintCommandListener.protocolReplyReceived(ProtocolCommandEvent) doesn't always use an end-of-line.

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 e0c54a74251d69caa366265ae0ff7237e5a32213
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 12:03:36 2025 -0500

    PrintCommandListener.protocolReplyReceived(ProtocolCommandEvent) doesn't
    always use an end-of-line.
---
 src/changes/changes.xml                                        | 1 +
 src/main/java/org/apache/commons/net/PrintCommandListener.java | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d15ae947..86dc933b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -84,6 +84,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate NtpUtils.NtpUtils().</action>
       <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>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">org.apache.commons.net.nntp.Article#getChild().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">org.apache.commons.net.nntp.Article#getNext().</action>
diff --git a/src/main/java/org/apache/commons/net/PrintCommandListener.java b/src/main/java/org/apache/commons/net/PrintCommandListener.java
index 51888441..bd6f55c7 100644
--- a/src/main/java/org/apache/commons/net/PrintCommandListener.java
+++ b/src/main/java/org/apache/commons/net/PrintCommandListener.java
@@ -180,7 +180,12 @@ public class PrintCommandListener implements ProtocolCommandListener {
         if (directionMarker) {
             writer.print("< ");
         }
-        writer.print(event.getMessage());
+        final String message = event.getMessage();
+        final char last = message.charAt(message.length() - 1);
+        writer.print(message);
+        if (last != '\r' && last != '\n') {
+            writer.println();
+        }
         writer.flush();
     }
 }