The session.connect() method is getting invoked, but only after
session.isConnected() has returned false.
Here's the basically what our getSession() does, I've simplified this snippet
for clarity, there is some locking and other stuff that doesn't pertain to this
issue in the application code.
private Session session;
public Session getSession() throws BinaryTransferSessionException {
if (session != null && session.isConnected()) {
return session;
}
try {
session = jsch.getSession(username, hostname, port);
session.setPassword(password);
.... set up session code ....
session.connect(); // protocol exception thrown from here
return session;
} catch (JSchException e) {
throw new BinaryTransferSessionException(
"Failed to set up session", e);
}
}
So basically if other parts of the code need the session, they call this and it
will give out the already connected session or connect then give them the
session.
Am I missing something here?
Thanks!
--Paul
-----Original Message-----
From: Atsuhiko Yamanaka [mailto:[email protected]]
Sent: Fri 1/7/2011 9:37 PM
To: Paul Sabatino
Cc: [email protected]
Subject: Re: [JSch-users] SSH Protocol error when trying to reconnect a session
Hi,
+-From: "Paul Sabatino" <[email protected]> --
|_Date: Fri, 7 Jan 2011 12:03:01 -0500 __________
|
|Our application is transferring data via SCP on a channel and randomly
|it will encounter the following error when transferring:
...
|The application then attempts to get a new session using:
|jsch.getSession(username, hostname, port);
|It fails to reconnect with the following error (partial stack trace):
|Caused by: com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 2 Protocol
|error: expected packet SSH_MSG_USERAUTH_REQUEST, got SSH_MSG_CHANNEL_OPEN
| at com.jcraft.jsch.Session.read(Session.java:899)
| at com.jcraft.jsch.UserAuthNone.start(UserAuthNone.java:85)
| at com.jcraft.jsch.Session.connect(Session.java:350)
It seems to me that Session#connect() method has been re-invoked.
Whenever establishing a new session, you need to get a new instance with
jsch.getSession(username, hostname, port);
and invoke its connect() method.
By the way, it seems the session is still alive,
because "SSH_MSG_CHANNEL_OPEN" has been returned.
Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
1-14-20 HONCHO AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.
Tel +81-22-723-2150
+1-415-578-3454
Skype callto://jcraft/
Twitter: http://twitter.com/ymnk
------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web. Learn how to
best implement a security strategy that keeps consumers' information secure
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users