GH-3123: Don't logout FtpSession if not connected
Fixes https://github.com/spring-projects/spring-integration/issues/3123
This commit is contained in:
@@ -38,6 +38,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @author Den Ivanov
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -154,7 +155,9 @@ public class FtpSession implements Session<FTPFile> {
|
||||
if (this.readingRaw.get() && !finalizeRaw() && LOGGER.isWarnEnabled()) {
|
||||
LOGGER.warn("Finalize on readRaw() returned false for " + this);
|
||||
}
|
||||
this.client.logout();
|
||||
if (this.client.isConnected()) {
|
||||
this.client.logout();
|
||||
}
|
||||
this.client.disconnect();
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
@@ -69,6 +69,7 @@ class SessionFactoryTests {
|
||||
sessionFactory.setDataTimeout(789);
|
||||
doReturn(200).when(client).getReplyCode();
|
||||
doReturn(true).when(client).login("foo", null);
|
||||
doReturn(true).when(client).isConnected();
|
||||
FtpSession session = sessionFactory.getSession();
|
||||
verify(client).setConnectTimeout(123);
|
||||
verify(client).setDefaultTimeout(456);
|
||||
@@ -210,7 +211,6 @@ class SessionFactoryTests {
|
||||
session.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
failures.incrementAndGet();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user