com.jcraft.jsch.JSchException: invalid server's version string

We have a scheduler service which will run for every three minutes. The service will login to the SFTP server and get the files from the server. While connecting to the SFTP server we are receiving intermittent errors. The following is the error

com.jcraft.jsch.JSchException: invalid server’s version string

Note: We have tried replacing the jar file jsch-0.1.31.jar file with the latest jsch-0.1.51.jar but, in both the scenarios we are receiving the same exception. The SFTP server version string is SSH-2.0-OpenSSH_5.3

May I know if anyone had this issue and what might be the reason? :roll:

Are you using the correct port. Did you restart the IS after placing the jars.

We are able to connect to the SFTP server. The error we are receiving is an intermittent error.

If it is intermittant then possible may be a bug or related to jars version etc…

HTH,
RMG

Yep! It is a bug in the JSch SFTP implementation and is already fixed in the version 0.1.20.

http://www.jcraft.com/jsch/ChangeLog

Though IS is using the 0.1.31 version we still have the issue, we have tried with the latest jar file which is 0.1.51 but it does not help. Just wanted to know if anyone had a similar issue.

jsch is open source, you can check the logic behind this error.

I think the error is generated by
com.jcraft.jsch.Session

for my version (0.1.42), it has:
if(i==buf.buffer.length ||
i<7 || // SSH-1.99 or SSH-2.0
(buf.buffer[4]==‘1’ && buf.buffer[6]!=‘9’) // SSH-1.5
){
throw new JSchException(“invalid server’s version string”);
}
break;
Does the server you are connecting has more than one instances? Since it’s intermittent, my guess is that one of the instance is running a version of SSH that is not supported by jsch.

Our server version string is SSH-2.0-OpenSSH_5.3

But how can we know the server we are connecting has more than one instances?

Thanks,
Ramakrishna

check whoever runs the server.
you can also enable logging, so you will see what’s the server version string is returned when it’s throwing that error. Check with jsch documentation for how to do logging.

Unfortunately, logging will not reveal the server version string that caused Session to throw the exception. The code that logs the version string comes immediately AFTER the code quoted in your post AFTER the exception is already thrown! Only well-formed version strings get logged. Sheesh.

It should be relatively easy to modify Session to log the version string as soon as it’s returned. Then, with logging enabled, the next time the error occurs you’ll be able to see the version string that caused it.

Great point, Perry!
Jsch is easy to modify & recompile, you can easily do it.
they should include this logging change in their core code base too, so you may also want to open a ticket with them.

I’ve opened the ticket with JCraft.