|
a/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/utils/SSHManager.java |
|
b/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/utils/SSHManager.java |
|
... |
|
... |
72 |
session.setConfig("StrictHostKeyChecking", "no");
|
72 |
session.setConfig("StrictHostKeyChecking", "no");
|
73 |
session.connect(timeout);
|
73 |
session.connect(timeout);
|
74 |
|
74 |
|
75 |
} catch (JSchException e) {
|
75 |
} catch (JSchException e) {
|
76 |
e.printStackTrace();
|
76 |
e.printStackTrace();
|
|
|
77 |
throw new SSHManagerException("Can not connect to machine "+fqdn+":"+port+". "+e.getLocalizedMessage());
|
77 |
}
|
78 |
}
|
78 |
return session;
|
79 |
return session;
|
79 |
}
|
80 |
}
|
80 |
|
81 |
|
81 |
public File readFile(Session session, String path) throws SSHManagerException{
|
82 |
public File readFile(Session session, String path) throws SSHManagerException{
|
|
... |
|
... |
102 |
ChannelSftp sftpChannel = (ChannelSftp) channel;
|
103 |
ChannelSftp sftpChannel = (ChannelSftp) channel;
|
103 |
|
104 |
|
104 |
File file = null;
|
105 |
File file = null;
|
105 |
try {
|
106 |
try {
|
106 |
file = File.createTempFile("tavernaExtractor-", ".input");
|
107 |
file = File.createTempFile("tavernaExtractor-", ".input");
|
|
|
108 |
sftpChannel.get(path, file.getAbsolutePath());
|
107 |
} catch (IOException e) {
|
109 |
} catch (SftpException | IOException e) {
|
108 |
e.printStackTrace();
|
110 |
e.printStackTrace();
|
109 |
throw new SSHManagerException(e.getLocalizedMessage());
|
111 |
throw new SSHManagerException("Can not read file '"+path.toString()+"' from remote machine. "+e.getLocalizedMessage());
|
110 |
}
|
|
|
111 |
|
|
|
112 |
try {
|
|
|
113 |
sftpChannel.get(path, file.getAbsolutePath());
|
|
|
114 |
} catch (SftpException e) {
|
|
|
115 |
e.printStackTrace();
|
|
|
116 |
throw new SSHManagerException(e.getLocalizedMessage());
|
|
|
117 |
}
|
112 |
}
|
118 |
|
113 |
|
119 |
sftpChannel.disconnect();
|
114 |
sftpChannel.disconnect();
|
120 |
session.disconnect();
|
115 |
session.disconnect();
|
121 |
return file;
|
116 |
return file;
|
|
... |
|
... |
135 |
|
130 |
|
136 |
Channel channel = null;
|
131 |
Channel channel = null;
|
137 |
try {
|
132 |
try {
|
138 |
channel = session.openChannel("sftp");
|
133 |
channel = session.openChannel("sftp");
|
139 |
channel.connect();
|
134 |
channel.connect();
|
|
|
135 |
ChannelSftp sftpChannel = (ChannelSftp) channel;
|
|
|
136 |
sftpChannel.put(from, to);
|
140 |
} catch (JSchException e) {
|
137 |
} catch (SftpException | JSchException e) {
|
141 |
e.printStackTrace();
|
138 |
e.printStackTrace();
|
142 |
throw new SSHManagerException(e.getLocalizedMessage());
|
139 |
throw new SSHManagerException("Can not save file from '"+from+"' to '"+to+"' on remote machine. "+e.getLocalizedMessage());
|
143 |
}
|
|
|
144 |
|
|
|
145 |
ChannelSftp sftpChannel = (ChannelSftp) channel;
|
|
|
146 |
|
|
|
147 |
try {
|
|
|
148 |
sftpChannel.put(from, to);
|
|
|
149 |
} catch (SftpException e) {
|
|
|
150 |
e.printStackTrace();
|
|
|
151 |
throw new SSHManagerException(e.getLocalizedMessage());
|
|
|
152 |
}
|
140 |
}
|
153 |
|
141 |
|
154 |
session.disconnect();
|
142 |
session.disconnect();
|
155 |
}
|
143 |
}
|
156 |
|
144 |
|
|
... |
|
... |
167 |
|
155 |
|
168 |
Channel channel = null;
|
156 |
Channel channel = null;
|
169 |
try {
|
157 |
try {
|
170 |
channel = session.openChannel("sftp");
|
158 |
channel = session.openChannel("sftp");
|
171 |
channel.connect();
|
159 |
channel.connect();
|
|
|
160 |
ChannelSftp sftpChannel = (ChannelSftp) channel;
|
|
|
161 |
sftpChannel.lstat(path.toString()); // if dir not exists an exception is thrown
|
172 |
} catch (JSchException e) {
|
162 |
}catch (SftpException | JSchException e) {
|
173 |
throw new SSHManagerException(e.getLocalizedMessage());
|
163 |
throw new SSHManagerException("Directory '"+path.toString()+"' does not exist on remote machine. " +e.getLocalizedMessage()+"!");
|
174 |
}
|
164 |
}
|
175 |
|
|
|
176 |
ChannelSftp sftpChannel = (ChannelSftp) channel;
|
|
|
177 |
try {
|
|
|
178 |
sftpChannel.lstat(path.toString()); // if dir not exists an exception is thrown
|
|
|
179 |
}catch (SftpException e) {
|
|
|
180 |
throw new SSHManagerException("Directory '"+path.toString()+"' does not exist on remote machine. " +e.getLocalizedMessage()+"!");
|
|
|
181 |
}
|
|
|
182 |
}
|
165 |
}
|
183 |
}
|
166 |
}
|