--- a/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/utils/SSHManager.java
+++ b/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/utils/SSHManager.java
@@ -74,6 +74,7 @@
} catch (JSchException e) {
e.printStackTrace();
+ throw new SSHManagerException("Can not connect to machine "+fqdn+":"+port+". "+e.getLocalizedMessage());
}
return session;
}
@@ -104,16 +105,10 @@
File file = null;
try {
file = File.createTempFile("tavernaExtractor-", ".input");
- } catch (IOException e) {
+ sftpChannel.get(path, file.getAbsolutePath());
+ } catch (SftpException | IOException e) {
e.printStackTrace();
- throw new SSHManagerException(e.getLocalizedMessage());
- }
-
- try {
- sftpChannel.get(path, file.getAbsolutePath());
- } catch (SftpException e) {
- e.printStackTrace();
- throw new SSHManagerException(e.getLocalizedMessage());
+ throw new SSHManagerException("Can not read file '"+path.toString()+"' from remote machine. "+e.getLocalizedMessage());
}
sftpChannel.disconnect();
@@ -137,18 +132,11 @@
try {
channel = session.openChannel("sftp");
channel.connect();
- } catch (JSchException e) {
+ ChannelSftp sftpChannel = (ChannelSftp) channel;
+ sftpChannel.put(from, to);
+ } catch (SftpException | JSchException e) {
e.printStackTrace();
- throw new SSHManagerException(e.getLocalizedMessage());
- }
-
- ChannelSftp sftpChannel = (ChannelSftp) channel;
-
- try {
- sftpChannel.put(from, to);
- } catch (SftpException e) {
- e.printStackTrace();
- throw new SSHManagerException(e.getLocalizedMessage());
+ throw new SSHManagerException("Can not save file from '"+from+"' to '"+to+"' on remote machine. "+e.getLocalizedMessage());
}
session.disconnect();
@@ -169,15 +157,10 @@
try {
channel = session.openChannel("sftp");
channel.connect();
- } catch (JSchException e) {
- throw new SSHManagerException(e.getLocalizedMessage());
+ ChannelSftp sftpChannel = (ChannelSftp) channel;
+ sftpChannel.lstat(path.toString()); // if dir not exists an exception is thrown
+ }catch (SftpException | JSchException e) {
+ throw new SSHManagerException("Directory '"+path.toString()+"' does not exist on remote machine. " +e.getLocalizedMessage()+"!");
}
-
- ChannelSftp sftpChannel = (ChannelSftp) channel;
- try {
- sftpChannel.lstat(path.toString()); // if dir not exists an exception is thrown
- }catch (SftpException e) {
- throw new SSHManagerException("Directory '"+path.toString()+"' does not exist on remote machine. " +e.getLocalizedMessage()+"!");
- }
}
}