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!

Community
  • 1
  • 1
user1935724
  • 554
  • 1
  • 6
  • 18

1 Answers1

0

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

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

Totoro
  • 615
  • 5
  • 11
  • 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? – user1935724 May 01 '14 at 21:54
  • ChannelSsh inherits methods for getting the input and output stream for this channel. One of those will have STDOUT. – Totoro May 01 '14 at 22:07