Search code examples
javajschremote-connection

unable to understand connection establishment code


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.


Solution

  • 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.