Skip to content

Commit 315fafd

Browse files
artembilangaryrussell
authored andcommitted
GH-3090: Add logout() to FtpSession.close()`
Fixes #3090 Without `logout()` the FTP session is not closed at all, but just the connection is closed. Some FTP servers close those sessions eventually anyway, but some just leak with resources. **Cherry-pick to 5.1.x & 4.3.x**
1 parent 35b964c commit 315fafd

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public void close() {
153153
}
154154
}
155155
}
156+
this.client.logout();
156157
this.client.disconnect();
157158
}
158159
catch (Exception e) {
@@ -196,7 +197,6 @@ public boolean rmdir(String directory) throws IOException {
196197
return this.client.removeDirectory(directory);
197198
}
198199

199-
200200
@Override
201201
public boolean exists(String path) throws IOException {
202202
Assert.hasText(path, "'path' must not be empty");

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@
4545
* @author Oleg Zhurakousky
4646
* @author Gunnar Hillert
4747
* @author Gary Russell
48+
* @author Artem Bilan
4849
*
4950
*/
5051
@SuppressWarnings({"rawtypes", "unchecked"})
5152
public class SessionFactoryTests {
5253

5354

5455
@Test
55-
public void testTimeouts() throws Exception {
56+
public void testFtpClientInteraction() throws Exception {
5657
final FTPClient client = mock(FTPClient.class);
5758
DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory() {
5859

@@ -67,10 +68,15 @@ protected FTPClient createClientInstance() {
6768
sessionFactory.setDataTimeout(789);
6869
doReturn(200).when(client).getReplyCode();
6970
doReturn(true).when(client).login("foo", null);
70-
sessionFactory.getSession();
71+
FtpSession session = sessionFactory.getSession();
7172
verify(client).setConnectTimeout(123);
7273
verify(client).setDefaultTimeout(456);
7374
verify(client).setDataTimeout(789);
75+
76+
session.close();
77+
78+
verify(client).logout();
79+
verify(client).disconnect();
7480
}
7581

7682
@Test

0 commit comments

Comments
 (0)