有人可以帮我解决如何使用spring sftp adapter在java代码中执行unix命令。我已经与该jar连接但不知道如何继续执行unix命令。
package automation;
import java.io.InputStream;
import org.springframework.integration.channel.ChannelPurger;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
import org.springframework.integration.sftp.session.SftpSession;
import com.jcraft.jsch.*;
public class unixConnect {
DefaultSftpSessionFactory dsftp;
String input1 = "/****/****/file.dat";
public DefaultSftpSessionFactory getDsftp() {
return dsftp;
}
public void setDsftp(DefaultSftpSessionFactory dsftp) {
this.dsftp = dsftp;
}
private Session sess;
public void connect() {
try {
sess = dsftp.getSession();
String command = "ksh /home/***/exec " + input1;
---- This is the place how to execute the above command.
channel.setInputStream(null);
channel.setOutputStream(System.out);
((ChannelExec)channel).setCommand( command );
((ChannelExec)channel).setErrStream(System.out);
channel.connect();
InputStream input = channel.getInputStream();
} catch (Exception e) {
System.out.println("Error" + e);
}
}
}
我一直在寻找答案,但没有得到答案。 :(