0
有人可以帮助我如何使用spring sftp适配器在java代码中执行unix命令。我已经与该jar进行了连接,但不知道如何继续执行unix命令。使用sftp弹簧适配器在java中执行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);
}
}
}
我一直在寻找它找到一个答案,但没有得到一个。 :(
SFTP与在linux中执行命令有什么关系Java已经提供了一种通过运行时库执行linux命令的方法,请检查一下。 –