sshj
sshj copied to clipboard
Provision in session maintenance
Is there any method available for the following scenario?
- Connect to SFTP Server through sshj implementation and upload some files.
- Next time we need to upload one file. It should use the existing session and upload the file. The session created in first step should maintain for the particular time. The next upload files should just re-use the session. If there is no upload in the particular period, the session will be closed. The next upload should connect, authenticate and reuse the session.
You will need to program this yourself. SSHJ does not by itself handle the reuse for you.
Op vr 22 mei 2020 om 12:42 schreef saravanakumarvijayakumar < [email protected]>:
Is there any method available for the following scenario?
- Connect to SFTP Server through sshj implementation and upload some files.
- Next time we need to upload one file. It should use the existing session and upload the file. The session created in first step should maintain for the particular time. The next upload files should just re-use the session. If there is no upload in the particular period, the session will be closed. The next upload should connect, authenticate and reuse the session.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hierynomus/sshj/issues/584, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA4XI3I244J6U7TQUGZ7WDRSZJITANCNFSM4NHVWCWA .
Is there any provision for setting the idle timeout for session closing automatically?
This is the gentle reminder for the above question.
@saravanakumarvijayakumar No there isn't. There is a keep alive mechanism available to keep connections (and thus sessions) alive.
I'm trying to do something similar as I would like to use exec
to execute multiple commands sequentially over a single SSH session. Is this something that is supported or would this require changes to SSHJ code?
@FabianHenneke You can open a shell for that :) Unless you don't know the commands beforehand, in which case I would suggest to cache the connected client by hostname.
@FabianHenneke You can open a shell for that :) Unless you don't know the commands beforehand, in which case I would suggest to cache the connected client by hostname.
I guess opening a shell would be a decent workaround, but I would try to avoid that if possible. I may be doing something wrong, but the following attempt at reusing a connected client leads to a "multiple sessions" error:
SSHClient client = new SSHClient();
client.connect(...);
client.auth(...);
Session session = client.startSession();
session.exec(...);
session.close(...);
client.startSession(); // throws an exception
Is there a way to start a second session after closing the first one?
No, at this moment the SSHClient is not reusable, which is also documented in the JavaDoc.
I took the JavaDoc to mean that a Session
is not reusable, but if it is indeed the SSHClient
that is not reusable, this fully explains why I am seeing the exception. I will try to use the shell then.
I took the JavaDoc to mean that a
Session
is not reusable, but if it is indeed theSSHClient
that is not reusable, this fully explains why I am seeing the exception. I will try to use the shell then.
As it turns out, SSHClient
(but not Session
) seems to support reuse: https://github.com/android-password-store/Android-Password-Store/pull/1012