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 953b5a3c FTPClient._storeFile(String, String, InputStream) doesn't
always close it's internal socket when an exception is thrown early in
processing.
953b5a3c is described below
commit 953b5a3cae00488b13d9dfe8d0c422736384f29f
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Mar 13 07:15:35 2026 -0400
FTPClient._storeFile(String, String, InputStream) doesn't always close
it's internal socket when an exception is thrown early in processing.
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/net/ftp/FTPClient.java | 20 ++++++++++----------
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 73e4c600..1ae61405 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -71,6 +71,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary
Gregory">TelnetInputStream now restores the current thread's interrupt flag
when catching InterruptedException.</action>
<action type="fix" dev="ggregory" due-to="Jianwei Guo, Gary Gregory"
issue="NET-740">FTP fails to parse listings for Linux vsftpd in Chinese or
Japanese #393.</action>
<action type="fix" dev="ggregory" due-to="Gary
Gregory">TelnetInputStream.read() doesn't preserve the original
InterruptedException as the cause of its InterruptedIOException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary
Gregory">FTPClient._storeFile(String, String, InputStream) doesn't always close
it's internal socket when an exception is thrown early in processing.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add
DatagramSocketClient.getDefaultTimeoutDuration() and deprecate
getDefaultTimeout().</action>
<action type="add" dev="ggregory" due-to="Maros Orsak, Gary Gregory"
issue="NET-741">Add subnet IPv6 handling with SubnetUtils6 #391.</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 5d001201..81239237 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -963,18 +963,18 @@ public class FTPClient extends FTP implements
Configurable {
if (socket == null) {
return false;
}
- final OutputStream output;
- if (fileType == ASCII_FILE_TYPE) {
- output = new
ToNetASCIIOutputStream(getBufferedOutputStream(socket.getOutputStream()));
- } else {
- output = getBufferedOutputStream(socket.getOutputStream());
- }
+ OutputStream output = null;
CSL csl = null;
- if (DurationUtils.isPositive(controlKeepAliveTimeout)) {
- csl = new CSL(this, controlKeepAliveTimeout,
controlKeepAliveReplyTimeout);
- }
- // Treat everything else as binary for now
try {
+ if (fileType == ASCII_FILE_TYPE) {
+ output = new
ToNetASCIIOutputStream(getBufferedOutputStream(socket.getOutputStream()));
+ } else {
+ output = getBufferedOutputStream(socket.getOutputStream());
+ }
+ if (DurationUtils.isPositive(controlKeepAliveTimeout)) {
+ csl = new CSL(this, controlKeepAliveTimeout,
controlKeepAliveReplyTimeout);
+ }
+ // Treat everything else as binary for now
Util.copyStream(local, output, getBufferSize(),
CopyStreamEvent.UNKNOWN_STREAM_SIZE, mergeListeners(csl), false);
output.close(); // ensure the file is fully written
socket.close(); // done writing the file