1

I am beginner in Java and as such I am having difficulty in understanding a piece of code.At this SO post the first two lines create a connection instance:

/* Create a connection instance */
Connection conn = new Connection(hostname);
/* Now connect */
conn.connect();

I am unable to get which library needs to be imported to support this? The post mentions use of JSch in the beginning but when I tried it then I couldn't where in JSch Connection class is declared? Any help will be useful for me.

Community
  • 1
  • 1
Jason Donnald
  • 2,256
  • 9
  • 36
  • 49

2 Answers2

2

JCraft JSCH can be used to perform SFTP and run remote commands with an SSH connection.

It does not use a Connection class. In JSCH you create a Session object, which contains connection information. You then connect the session object, then create Channel objects to send input/receive output.

Here is the session API documentation for JSCH.

Here are some examples from JCraft.

There have been quite a few JSCH questions asked here on Stack overflow, some of which include working code you could use to try it out.

Community
  • 1
  • 1
Damienknight
  • 1,876
  • 2
  • 18
  • 34
0

I would guess that the Connection class you mention is ch.ethz.ssh2.Connection. It's mentioned in import directives in code samples here and here. This class looks to be in a JAR named ganymed-ssh2.jar.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
  • The poster in the linked question states he is using something called Jsch. Ganymed is a good SSH library, and it does have a Connection class, but it isn't called Jsch. – user207421 Aug 26 '14 at 08:13
  • @EJP: The class I linked to has the constructor and all methods mentioned in the code sample in the linked question, and the [Session](http://www.ganymed.ethz.ch/ssh2/javadoc/ch/ethz/ssh2/Session.html) class also has the methods mentioned in that code sample. So I believe that the Ganymed library is being used. Perhaps the poster in the linked question was mistaken about using JSch? – Luke Woodward Aug 26 '14 at 08:31