mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 07:10:53 +03:00
Close Session when closing SCPEngine or SFTPEngine (#926)
Co-authored-by: Jeroen van Erp <jeroen@hierynomus.com>
This commit is contained in:
@@ -48,6 +48,7 @@ public class SFTPEngine
|
||||
|
||||
protected final PathHelper pathHelper;
|
||||
|
||||
private final Session session;
|
||||
protected final Session.Subsystem sub;
|
||||
protected final PacketReader reader;
|
||||
protected final OutputStream out;
|
||||
@@ -63,7 +64,7 @@ public class SFTPEngine
|
||||
|
||||
public SFTPEngine(SessionFactory ssh, String pathSep)
|
||||
throws SSHException {
|
||||
Session session = ssh.startSession();
|
||||
session = ssh.startSession();
|
||||
loggerFactory = session.getLoggerFactory();
|
||||
log = loggerFactory.getLogger(getClass());
|
||||
sub = session.startSubsystem("sftp");
|
||||
@@ -346,6 +347,7 @@ public class SFTPEngine
|
||||
throws IOException {
|
||||
sub.close();
|
||||
reader.interrupt();
|
||||
session.close();
|
||||
}
|
||||
|
||||
protected LoggerFactory getLoggerFactory() {
|
||||
|
||||
@@ -19,6 +19,7 @@ import net.schmizz.sshj.common.IOUtils;
|
||||
import net.schmizz.sshj.common.LoggerFactory;
|
||||
import net.schmizz.sshj.common.SSHException;
|
||||
import net.schmizz.sshj.common.StreamCopier;
|
||||
import net.schmizz.sshj.connection.channel.direct.Session;
|
||||
import net.schmizz.sshj.connection.channel.direct.Session.Command;
|
||||
import net.schmizz.sshj.connection.channel.direct.SessionFactory;
|
||||
import net.schmizz.sshj.xfer.TransferListener;
|
||||
@@ -41,6 +42,7 @@ class SCPEngine {
|
||||
private final SessionFactory host;
|
||||
private final TransferListener listener;
|
||||
|
||||
private Session session;
|
||||
private Command scp;
|
||||
private int exitStatus;
|
||||
|
||||
@@ -82,7 +84,8 @@ class SCPEngine {
|
||||
|
||||
void execSCPWith(ScpCommandLine commandLine)
|
||||
throws SSHException {
|
||||
scp = host.startSession().exec(commandLine.toCommandLine());
|
||||
session = host.startSession();
|
||||
scp = session.exec(commandLine.toCommandLine());
|
||||
}
|
||||
|
||||
void exit() {
|
||||
@@ -102,6 +105,10 @@ class SCPEngine {
|
||||
log.warn("SCP exit signal: {}", scp.getExitSignal());
|
||||
}
|
||||
}
|
||||
if(session != null) {
|
||||
IOUtils.closeQuietly(session);
|
||||
session = null;
|
||||
}
|
||||
|
||||
scp = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user