[
https://issues.apache.org/jira/browse/SSHD-935?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16895813#comment-16895813
]
Goldstein Lyor commented on SSHD-935:
-------------------------------------
This issue is better discussed on the [email protected] mailing list since it
is a not a real "issue". However, a few things stand out in the code snippet
above:
# The {{SshClient}} should be set-up and {{start()}}-ed *once* - in the _main_
initialization and not every time an SFTP connection occurs (it should also be
{{stop()}}-ed when _main_ exits)
# The call to _session.auth()_ should occur *before* any channels, SFTP, SCP,
etc. is attempted on the session. In this context, the call to check {{if
(session.isAuthenticated())}} is *redundant*- if _auth.verify()_ did not throw
an exception it cannot be anything *but* authenticated.
# Why is the code creating a shell channel if all it does is SFTP ?
# I don't see calls to _session.close()_, _sftpClient.close()_. Perhaps you
are closing the session while your code is still attempting to use the SFTP
client created through it. Note that the resources are co-dependent - i.e., if
you close the session then *all* SFTP instances created through it die with it
(and the session dies if the client is stopped). Make sure that you do not
close the session until you are done using SFTP (or SCP or any channel created
through it)
> Synchronizing the Apache Mina client connection between thread
> --------------------------------------------------------------
>
> Key: SSHD-935
> URL: https://issues.apache.org/jira/browse/SSHD-935
> Project: MINA SSHD
> Issue Type: Question
> Affects Versions: 2.2.0
> Reporter: Zabee Ulla
> Priority: Major
>
> I have multiple threads accessing a prototype bean
> SFTPMinaClientConnector.java. Every thread has some random method whose
> entire job is to connect to a remote machine using the
> SFTPMinaClientConnector.java, get the job done and disconnect.
> The problem I am facing is connection synchronization. While one thread is
> still doing some task the other closes it resulting in connection already
> closed exception.
> Looks like every thread is using the same connection.
> Is it possible to get a different connection for every thread? If so, how
> can I do that?
> If not, how can I synchronize the connection? Is there something in Mina
> APIs that can help in this situation?
> Below is the connect() method from my SFTPMinaClientConnector.java through
> which every thread goes in
> public void connect(){
> try {
> SshClient _client = SshClient.setUpDefaultClient();
> _client.start();
> ConnectFuture connectFuture = _client.connect(_username, _host, portNumber);
> connectFuture.awaitUninterruptibly();
> _session = connectFuture.getSession();
> _session.addPasswordIdentity(_password);
> shellChannel = _session.createShellChannel();
> _session.auth().verify(30000L);
> if (_session.isAuthenticated())
> { LOG.debug("Authentication succeeded. SFTP channel opened and connected."); }
> sftpClient = SftpClientFactory.instance().createSftpClient(_session);
> }
> catch (Exception oie) \{ .... }
> }
> Thank you in advance,
> Zabee
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]