您好我正在使用Zeon库实现一个sftp客户端,它工作正常。当我测试失败时,问题就出现了,这是我的代码:
int status = 0;
try {
SFTPClient sftpClient = new SFTPClient(host, username, password);
status = sftpClient.sendFolder(sendingFolder, destFolder, new BatchTransferProgressDefault());
System.out.println("FileTransferStatus.SUCCESS: " + FileTransferStatus.SUCCESS);
System.out.println("status: " + status);
}catch (FileTransferException e){
LOGGER.error(e);
}catch (Exception e2){
LOGGER.error(e2);
}
所以我输入了错误的主机,用户名和密码,状态标志仍然返回true,即使我的控制台显示异常并且它也没有进入我的异常。
有谁知道如何强制zeon库进入我的异常块? 提前致谢
答案 0 :(得分:0)
你的问题是这可能发生了:
boolean status = true;
// ... status flag doesn't ever get set to false ...
try {
SFTPClient sftpClient = new SFTPClient(host, username, password);
// Your error is thrown before you get this far.
status = sftpClient.sendFolder(sendingFolder, destFolder, new BatchTransferProgressDefault());
System.out.println("FileTransferStatus.SUCCESS: " + FileTransferStatus.SUCCESS);
System.out.println("status: " + status);
} catch (FileTransferException e){
// The error is logged which means you'll only see it wherever you log it.
LOGGER.error(e);
} catch (Exception e2){
LOGGER.error(e2);
}