create tunnel connection via ssh (JAVA) to type commands in PUTTY console

1

Good morning, cordial greeting.

I have a problem that I have not been able to solve, it turns out that I need to automate a process which consists of a desktop test, the process is:

Enter the PUTTY with its respective host name and port, then enter the username and password data, after login enter a command.

It's a very brief thing, but I really have not found how to do it, I've already used the Jsch library for connections via SSH but I can not find the way. Greetings.

    
asked by Mauricio Puerta 24.05.2017 в 16:19
source

1 answer

1

Using that library you should do the following:

JSch jsch = new JSch();
Session session = jsch.getSession(usuario, host, 22);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
Channel channel = session.openChannel("shell");

DataInputStream dataIn = new DataInputStream(channel.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(dataIn));
DataOutputStream dataOut = new DataOutputStream(channel.getOutputStream());

dataOut.writeBytes("mi comando\r\n");

I also leave you a link to the same stackoverflow question in English, in case it helps you too. link

    
answered by 24.05.2017 в 19:22