Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started