I am trying to run a program which process a file from window using jcraft library in Unix. what i found after establishing the channel it always try to run the program in home directory but i need to run in a separate directory.please have a look what i tried so far and let me know what i am missing.
String strRemoteDir = "/home/process/input" channel = session.openChannel("sftp");
channel.connect();
System.out.println("sftp channel opened and connected.");
channelSftp = (ChannelSftp) channel;
// Printing Home Directory in Unix Server
System.out.println(channelSftp.getHome());
channelSftp.cd(strRemoteDir);
System.out.println(channelSftp.pwd());
// for uploading a file where i need to run the program
File f = new File(fileName);
channelSftp.put(new FileInputStream(f), f.getName());
System.out.println("File transfered successfully to host.");
fileTransfer = true;
channel=session.openChannel("exec");
InputStream in=channel.getInputStream();
// it is printing the desired directory where i want to go
System.out.println(channelSftp.pwd());
((ChannelExec)channel).setCommand("sh process.ksh "a.txt");
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
channel.connect();
output : process.ksh not found
But through putty i was able to run the program. just to let you know process.ksh is not in the input directory, but has the capability to run from anywhere with arguments. ((ChannelExec)channel).setcommand("ls") prints out all the files from home directory. i believe i am establishing a channel to home directory, i just don't know how to run bash program using jcraft in a desired location.Please let me know what i am missing or is it possible to make it happen.
Thanks in advance. Nur