Reputation: 263
Hi I am currently using the below code line to issue commands to the remote server
ChannelSftp sftp = (ChannelSftp)session.openChannel("sftp");
sftp.connect();
System.out.println("Current Directory: " + sftp.pwd());
<= This Line
But pwd is already be defined as a method in Class ChannelSftp, My Question is what if I want to issue some command or run any .sh file which is not a method in JSch?
Let say if I want to run : sudo /opt/bin/run.sh file.
OR is there any method which I can use to do the job
(Kindly note I have a Jump Server in between localhost and web Server. And web server can only be accessed via the jump server.So that is the reason I am not using exec or shell).
Upvotes: 0
Views: 547
Reputation: 14651
The ChannelSftp class is implementing the SFTP protocol, which is cabable of preforming FTP operations. Executing a random command is clearly not permitted via SFTP. What you need in this case is using a different class of the jsch lib: ChannelExec.
Example is here.
Upvotes: 1