0

I want to connect to a server using ssh and run an executable on the server from my local Java code. I am aware of the thread SSH connection with Java but the trouble is I can not figure out how to use sftpChannel (an object of ChannelSftp) to run a file rather than open a file.

If this can not be done using JSch, how should I do if I want to call a exe file remotely in Java.

Thanks very much!

1 Answer 1

0

You need to use ChannelSsh, not ChannelSftp to run a remote command.

http://epaul.github.io/jsch-documentation/javadoc/

Sign up to request clarification or add additional context in comments.

2 Comments

Would you mind to elaborate a bit more here, firstly are you suggesting using ChannelExec? Then I need to set the commands using void setCommand(String command)? Then calling run()? But how do I get the standard output from this executable?
ChannelSsh inherits methods for getting the input and output stream for this channel. One of those will have STDOUT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.