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
The following commit(s) were added to refs/heads/master by this push:
new 68e9e45c Add Add
org.apache.commons.net.ftp.FTPClient.getSystemTypeOverride()
68e9e45c is described below
commit 68e9e45cb6ed5b24f1497b5af1ffdade7ae63bca
Author: Gary D. Gregory <[email protected]>
AuthorDate: Wed Jul 16 10:54:35 2025 -0400
Add Add org.apache.commons.net.ftp.FTPClient.getSystemTypeOverride()
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/net/ftp/FTPClient.java | 68 +++++++++++++---------
2 files changed, 42 insertions(+), 27 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a6227056..27f42679 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -106,6 +106,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="Gary Gregory">Add --OPTS to
FTPClientExample.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory"
issue="NET-727">Add accessing options map for TFTP request packet and allow
using 'blksize' option #331.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add
org.apache.commons.net.util.ListenerList.isEmpty().</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add
org.apache.commons.net.ftp.FTPClient.getSystemTypeOverride().</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory,
Dependabot">Bump org.apache.commons:commons-parent from 70 to 85 #261, #278,
#280, #285, #298, #293, #300, #345.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory,
Dependabot">Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.18.0 #268,
#273, #281, #354.</action>
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 e3f812b4..3474a629 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -379,21 +379,6 @@ public class FTPClient extends FTP implements Configurable
{
static final Properties PROPERTIES =
loadResourceProperties(SYSTEM_TYPE_PROPERTIES);
}
- static Properties loadResourceProperties(final String
systemTypeProperties) {
- Properties properties = null;
- if (systemTypeProperties != null) {
- try (InputStream inputStream =
FTPClient.class.getResourceAsStream(systemTypeProperties)) {
- if (inputStream != null) {
- properties = new Properties();
- properties.load(inputStream);
- }
- } catch (final IOException ignore) {
- // ignore
- }
- }
- return properties;
- }
-
/**
* The system property ({@value}) which can be used to override the system
type.<br>
* If defined, the value will be used to create any automatically created
parsers.
@@ -468,6 +453,21 @@ public class FTPClient extends FTP implements Configurable
{
return PropertiesSingleton.PROPERTIES;
}
+ static Properties loadResourceProperties(final String
systemTypeProperties) {
+ Properties properties = null;
+ if (systemTypeProperties != null) {
+ try (InputStream inputStream =
FTPClient.class.getResourceAsStream(systemTypeProperties)) {
+ if (inputStream != null) {
+ properties = new Properties();
+ properties.load(inputStream);
+ }
+ } catch (final IOException ignore) {
+ // ignore
+ }
+ }
+ return properties;
+ }
+
/**
* Parse the path from a CWD reply.
* <p>
@@ -1241,7 +1241,7 @@ public class FTPClient extends FTP implements
Configurable {
} else // if no parserKey was supplied, check for a configuration
// in the params, and if it has a non-empty system type, use that.
- if (ftpClientConfig != null &&
ftpClientConfig.getServerSystemKey().length() > 0) {
+ if (ftpClientConfig != null &&
!ftpClientConfig.getServerSystemKey().isEmpty()) {
entryParser =
parserFactory.createFileEntryParser(ftpClientConfig);
entryParserKey = ftpClientConfig.getServerSystemKey();
} else {
@@ -1249,17 +1249,7 @@ public class FTPClient extends FTP implements
Configurable {
// hasn't been supplied, and the override property is not set
// then autodetect by calling
// the SYST command and use that to choose the parser.
- String systemType = System.getProperty(FTP_SYSTEM_TYPE);
- if (systemType == null) {
- systemType = getSystemType(); // cannot be null
- final Properties override = getOverrideProperties();
- if (override != null) {
- final String newType =
override.getProperty(systemType);
- if (newType != null) {
- systemType = newType;
- }
- }
- }
+ final String systemType = getSystemTypeOverride();
if (ftpClientConfig != null) { // system type must have been
empty above
entryParser = parserFactory.createFileEntryParser(new
FTPClientConfig(systemType, ftpClientConfig));
} else {
@@ -1877,6 +1867,30 @@ public class FTPClient extends FTP implements
Configurable {
return systemName;
}
+ /**
+ * Gets the system type from the {@link #FTP_SYSTEM_TYPE} system property,
or the server (@link #getSystemType()}, or the {@link #SYSTEM_TYPE_PROPERTIES}
+ * property file.
+ *
+ * @return The system type obtained from the server.
+ * @throws IOException If an I/O error occurs while either sending a
command to the server or receiving a reply from the server (and the default
system type
+ * property is not defined)
+ * @since 3.12.0
+ */
+ public String getSystemTypeOverride() throws IOException {
+ String systemType = System.getProperty(FTP_SYSTEM_TYPE);
+ if (systemType == null) {
+ systemType = getSystemType(); // cannot be null
+ final Properties override = getOverrideProperties();
+ if (override != null) {
+ final String newType = override.getProperty(systemType);
+ if (newType != null) {
+ systemType = newType;
+ }
+ }
+ }
+ return systemType;
+ }
+
/**
* Queries the server for a supported feature. Caches the parsed response
to avoid resending the command repeatedly.
*