Question: Is it possible to get a response from a ssh server in java code? I am trying to get a response from ssh server from

Is it possible to get a response from a ssh server in java code?

I am trying to get a response from ssh server from my java code with this code, not sure where i am wrong,

public static String runCommandAndReturn(String hostName, String username, String password, String command, String sshUser) throws IOException, OperationNotSuccessfulException { connect(hostName, username, password); clientChannel = session.createChannel(ClientChannel.CHANNEL_EXEC, command); ByteArrayOutputStream out = new ByteArrayOutputStream(); String response = out.toString(); clientChannel.setOut(new NoCloseOutputStream(out)); clientChannel.setErr(new NoCloseOutputStream(out)); clientChannel.open().await(); clientChannel.waitFor(Collections.singleton(ClientChannelEvent.CLOSED), 2000); out.reset(); return response; }

my command is like this :

find /app/weblogic/prestige/outbound/mis -type f -name 'VET_20230117*'*. Please help , thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!