Site icon TestingDocs.com

What is JSch?

Introduction

JSch stands for Java Secure Shell. It allows you to connect to an ssh remote server. SSH stands for Secure Shell. It provides support for secure remote login, secure file transfer, etc. It can automatically encrypt, authenticate, and compress transmitted data.

You can find more information about the JSch library at http://www.jcraft.com/jsch/

 

We can use this library in Java automation and in automation frameworks where you need to connect , copy files to remote machines without manual intervention. Using this library you can also connect to cloud machines in a secure way automatically. You can easily integrate the JSch library into your automation code using Maven build tool.

JSch Code Examples

You can find some bunch of simple Java programs, which demonstrates various JSch Features. Here is the link where you can find them:

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

Maven Dependency

In order to use the library in your automation, simply add this dependency to your existing pom.xml file. You may need to update your project after adding this to your project. JSch library is available on Maven central repository. In-case you need the latest library jar you can check the Central repository.

<dependency>
 <groupId>com.jcraft</groupId>
 <artifactId>jsch</artifactId>
 <version>0.1.54</version>
 </dependency>

 

Usage

You can instantiate and get a connection using JSch class as shown below. The Session object with username and host is required. The TCP port 22 will be used in making the connection. TCP connection will be established when you invoke session.connect().

JSch jsch = new JSch();
session = jsch.getSession(username, hostname, port);

……

session.connect();

 

Exit mobile version