Skip to content

Commit 953b5a3

Browse files
committed
FTPClient._storeFile(String, String, InputStream) doesn't always close
it's internal socket when an exception is thrown early in processing.
1 parent 749d03d commit 953b5a3

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ The <action> type attribute can be add,update,fix,remove.
7171
<action type="fix" dev="ggregory" due-to="Gary Gregory">TelnetInputStream now restores the current thread's interrupt flag when catching InterruptedException.</action>
7272
<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>
7373
<action type="fix" dev="ggregory" due-to="Gary Gregory">TelnetInputStream.read() doesn't preserve the original InterruptedException as the cause of its InterruptedIOException.</action>
74+
<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>
7475
<!-- ADD -->
7576
<action type="add" dev="ggregory" due-to="Gary Gregory">Add DatagramSocketClient.getDefaultTimeoutDuration() and deprecate getDefaultTimeout().</action>
7677
<action type="add" dev="ggregory" due-to="Maros Orsak, Gary Gregory" issue="NET-741">Add subnet IPv6 handling with SubnetUtils6 #391.</action>

src/main/java/org/apache/commons/net/ftp/FTPClient.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -963,18 +963,18 @@ protected boolean _storeFile(final String command, final String remote, final In
963963
if (socket == null) {
964964
return false;
965965
}
966-
final OutputStream output;
967-
if (fileType == ASCII_FILE_TYPE) {
968-
output = new ToNetASCIIOutputStream(getBufferedOutputStream(socket.getOutputStream()));
969-
} else {
970-
output = getBufferedOutputStream(socket.getOutputStream());
971-
}
966+
OutputStream output = null;
972967
CSL csl = null;
973-
if (DurationUtils.isPositive(controlKeepAliveTimeout)) {
974-
csl = new CSL(this, controlKeepAliveTimeout, controlKeepAliveReplyTimeout);
975-
}
976-
// Treat everything else as binary for now
977968
try {
969+
if (fileType == ASCII_FILE_TYPE) {
970+
output = new ToNetASCIIOutputStream(getBufferedOutputStream(socket.getOutputStream()));
971+
} else {
972+
output = getBufferedOutputStream(socket.getOutputStream());
973+
}
974+
if (DurationUtils.isPositive(controlKeepAliveTimeout)) {
975+
csl = new CSL(this, controlKeepAliveTimeout, controlKeepAliveReplyTimeout);
976+
}
977+
// Treat everything else as binary for now
978978
Util.copyStream(local, output, getBufferSize(), CopyStreamEvent.UNKNOWN_STREAM_SIZE, mergeListeners(csl), false);
979979
output.close(); // ensure the file is fully written
980980
socket.close(); // done writing the file

0 commit comments

Comments
 (0)