【发布时间】:2014-01-11 09:38:37
【问题描述】:
我正在使用以下代码通过 Jsch 运行 SFTP 命令:
public void putfile(){
try {
String command="winscp /script=D:\\command.txt" ;
System.out.println(command);
Runtime rt=Runtime.getRuntime();
rt.exec(command);
}
catch(Exception e) {
System.out.println("Exception in index.jsp:"+e.getMessage());
}
}
我正在将 sample.zip 从本地机器放到 Unix 服务器,
command.txt 包含:
option confirm off
open sftp:User:password@IP
get G:\sample.zip /MyFolderLocation/
exit
它工作正常,但每当 SFTP 进程失败时我都没有收到任何异常。有什么方法可以处理它吗?
【问题讨论】:
-
那不是 jsch。那是runtime.exec。这些是完全不同的东西。
-
@RobinGreen:我知道。我想说的是,我在使用 Jsch jar 文件的代码中使用了运行时类。那么,有没有办法处理呢?
-
我认为 Jsch 根本与这个问题无关,只是它可能提供有用的答案。
标签: java windows unix runtime.exec winscp