Skip to content

Commit c6358a9

Browse files
divartembilan
authored andcommitted
GH-3123: Don't logout FtpSession if not connected
Fixes #3123
1 parent 1334c75 commit c6358a9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/FtpSession.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @author Oleg Zhurakousky
3939
* @author Gary Russell
4040
* @author Artem Bilan
41+
* @author Den Ivanov
4142
*
4243
* @since 2.0
4344
*/
@@ -154,7 +155,9 @@ public void close() {
154155
if (this.readingRaw.get() && !finalizeRaw() && LOGGER.isWarnEnabled()) {
155156
LOGGER.warn("Finalize on readRaw() returned false for " + this);
156157
}
157-
this.client.logout();
158+
if (this.client.isConnected()) {
159+
this.client.logout();
160+
}
158161
this.client.disconnect();
159162
}
160163
catch (Exception e) {

spring-integration-ftp/src/test/java/org/springframework/integration/ftp/session/SessionFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected FTPClient createClientInstance() {
6969
sessionFactory.setDataTimeout(789);
7070
doReturn(200).when(client).getReplyCode();
7171
doReturn(true).when(client).login("foo", null);
72+
doReturn(true).when(client).isConnected();
7273
FtpSession session = sessionFactory.getSession();
7374
verify(client).setConnectTimeout(123);
7475
verify(client).setDefaultTimeout(456);
@@ -210,7 +211,6 @@ void testConnectionLimit() throws Exception {
210211
session.close();
211212
}
212213
catch (Exception e) {
213-
e.printStackTrace();
214214
failures.incrementAndGet();
215215
}
216216
});

0 commit comments

Comments
 (0)