File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
src/main/java/net/schmizz/sshj Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ public class SFTPEngine
4848
4949 protected final PathHelper pathHelper ;
5050
51+ private final Session session ;
5152 protected final Session .Subsystem sub ;
5253 protected final PacketReader reader ;
5354 protected final OutputStream out ;
@@ -63,7 +64,7 @@ public SFTPEngine(SessionFactory ssh)
6364
6465 public SFTPEngine (SessionFactory ssh , String pathSep )
6566 throws SSHException {
66- Session session = ssh .startSession ();
67+ session = ssh .startSession ();
6768 loggerFactory = session .getLoggerFactory ();
6869 log = loggerFactory .getLogger (getClass ());
6970 sub = session .startSubsystem ("sftp" );
@@ -346,6 +347,7 @@ public void close()
346347 throws IOException {
347348 sub .close ();
348349 reader .interrupt ();
350+ session .close ();
349351 }
350352
351353 protected LoggerFactory getLoggerFactory () {
Original file line number Diff line number Diff line change 1919import net .schmizz .sshj .common .LoggerFactory ;
2020import net .schmizz .sshj .common .SSHException ;
2121import net .schmizz .sshj .common .StreamCopier ;
22+ import net .schmizz .sshj .connection .channel .direct .Session ;
2223import net .schmizz .sshj .connection .channel .direct .Session .Command ;
2324import net .schmizz .sshj .connection .channel .direct .SessionFactory ;
2425import net .schmizz .sshj .xfer .TransferListener ;
@@ -41,6 +42,7 @@ class SCPEngine {
4142 private final SessionFactory host ;
4243 private final TransferListener listener ;
4344
45+ private Session session ;
4446 private Command scp ;
4547 private int exitStatus ;
4648
@@ -82,7 +84,8 @@ void cleanSlate() {
8284
8385 void execSCPWith (ScpCommandLine commandLine )
8486 throws SSHException {
85- scp = host .startSession ().exec (commandLine .toCommandLine ());
87+ session = host .startSession ();
88+ scp = session .exec (commandLine .toCommandLine ());
8689 }
8790
8891 void exit () {
@@ -102,6 +105,10 @@ void exit() {
102105 log .warn ("SCP exit signal: {}" , scp .getExitSignal ());
103106 }
104107 }
108+ if (session != null ) {
109+ IOUtils .closeQuietly (session );
110+ session = null ;
111+ }
105112
106113 scp = null ;
107114 }
You can’t perform that action at this time.
0 commit comments