Skip to content

Commit a62527a

Browse files
committed
Rework FTPClientWrapper.disconnect() to remove any chance of a new
connection being created on demand
1 parent 861ec2c commit a62527a

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public boolean abort() throws IOException {
7171
// it should be better to really "abort" the transfer, but
7272
// currently I didn't manage to make it work - so lets "abort" the hard way.
7373
// return getFtpClient().abort();
74-
7574
disconnect();
7675
return true;
7776
} catch (final IOException e) {
@@ -145,17 +144,19 @@ public boolean deleteFile(final String relPath) throws IOException {
145144

146145
@Override
147146
public void disconnect() throws IOException {
148-
try {
149-
getFtpClient().quit();
150-
} catch (final IOException e) {
151-
LOG.debug("I/O exception while trying to quit, probably it's a timed out connection, ignoring.", e);
152-
} finally {
147+
if (ftpClient != null) {
153148
try {
154-
getFtpClient().disconnect();
149+
ftpClient.quit();
155150
} catch (final IOException e) {
156-
LOG.warn("I/O exception while trying to disconnect, probably it's a closed connection, ignoring.", e);
151+
LOG.debug("I/O exception while trying to quit, connection likely timed out, ignoring.", e);
157152
} finally {
158-
ftpClient = null;
153+
try {
154+
getFtpClient().disconnect();
155+
} catch (final IOException e) {
156+
LOG.warn("I/O exception while trying to disconnect, connection likely closed, ignoring.", e);
157+
} finally {
158+
ftpClient = null;
159+
}
159160
}
160161
}
161162
}

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The <action> type attribute can be add,update,fix,remove.
4747
<body>
4848
<release version="2.11.0" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required.">
4949
<!-- FIX -->
50+
<action dev="ggregory" type="update" due-to="Gary Gregory">Rework FTPClientWrapper.disconnect() to remove any chance of a new connection being created on demand.</action>
5051
<!-- ADD -->
5152
<action dev="ggregory" type="update" due-to="Gary Gregory">Add org.apache.commons.vfs2.provider.ftp.FTPClientWrapper.sendOptions(String, String).</action>
5253
<action dev="ggregory" type="update" due-to="Gary Gregory">Add FtpFileSystemConfigBuilder.getControlEncodingCharset(FileSystemOptions) and deprecate getControlEncoding(FileSystemOptions).</action>

0 commit comments

Comments
 (0)