|
a/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/utils/SSHManager.java |
|
b/src/main/java/net/timbusproject/extractors/modules/tavernaextractor/utils/SSHManager.java |
|
... |
|
... |
2 |
|
2 |
|
3 |
import com.jcraft.jsch.*;
|
3 |
import com.jcraft.jsch.*;
|
4 |
|
4 |
|
5 |
import java.io.File;
|
5 |
import java.io.File;
|
6 |
import java.io.IOException;
|
6 |
import java.io.IOException;
|
7 |
import java.io.InputStream;
|
7 |
import java.lang.String;
|
8 |
import java.lang.Exception;import java.lang.String;import java.nio.file.Path;
|
8 |
import java.nio.file.Files;
|
9 |
import java.nio.file.Paths;
|
9 |
import java.nio.file.Path;
|
10 |
|
10 |
|
11 |
/**
|
11 |
/**
|
12 |
* Created by marco unterberger on 28.08.2014.
|
12 |
* Created by marco unterberger on 28.08.2014.
|
13 |
*
|
13 |
*
|
14 |
* Copy input files from a remote location to use them for the extraction.
|
14 |
* Copy input files from a remote location to use them for the extraction.
|
|
... |
|
... |
35 |
|
35 |
|
36 |
Session session = null;
|
36 |
Session session = null;
|
37 |
try {
|
37 |
try {
|
38 |
session = jsch.getSession(username, fqdn, port);
|
38 |
session = jsch.getSession(username, fqdn, port);
|
39 |
session.setPassword(password);
|
39 |
session.setPassword(password);
|
|
|
40 |
/*
|
|
|
41 |
From jsch README:
|
|
|
42 |
StrictHostKeyChecking: ask | yes | no
|
|
|
43 |
default: ask
|
|
|
44 |
If this property is set to ``yes'', jsch will never automatically add
|
|
|
45 |
host keys to the $HOME/.ssh/known_hosts file, and refuses to connect
|
|
|
46 |
to hosts whose host key has changed. This property forces the user
|
|
|
47 |
to manually add all new hosts. If this property is set to ``no'',
|
|
|
48 |
jsch will automatically add new host keys to the user known hosts
|
|
|
49 |
files. If this property is set to ``ask'', new host keys will be
|
|
|
50 |
added to the user known host files only after the user has confirmed
|
|
|
51 |
that is what they really want to do, and jsch will refuse to connect
|
|
|
52 |
to hosts whose host key has changed.
|
|
|
53 |
*/
|
40 |
session.setConfig("StrictHostKeyChecking", "no");
|
54 |
session.setConfig("StrictHostKeyChecking", "no");
|
41 |
session.connect(timeout);
|
55 |
session.connect(timeout);
|
42 |
|
56 |
|
43 |
} catch (JSchException e) {
|
57 |
} catch (JSchException e) {
|
44 |
e.printStackTrace();
|
58 |
e.printStackTrace();
|
|
... |
|
... |
119 |
throw new SSHManagerException(e.getLocalizedMessage());
|
133 |
throw new SSHManagerException(e.getLocalizedMessage());
|
120 |
}
|
134 |
}
|
121 |
|
135 |
|
122 |
session.disconnect();
|
136 |
session.disconnect();
|
123 |
}
|
137 |
}
|
|
|
138 |
|
|
|
139 |
public void directoryExists(Session session, Path... paths) throws SSHManagerException{
|
|
|
140 |
|
|
|
141 |
if(!session.isConnected()){
|
|
|
142 |
try{
|
|
|
143 |
session.connect();
|
|
|
144 |
}
|
|
|
145 |
catch (JSchException e){
|
|
|
146 |
throw new SSHManagerException(e.getLocalizedMessage());
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
Channel channel = null;
|
|
|
151 |
try {
|
|
|
152 |
channel = session.openChannel("sftp");
|
|
|
153 |
channel.connect();
|
|
|
154 |
} catch (JSchException e) {
|
|
|
155 |
throw new SSHManagerException(e.getLocalizedMessage());
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
ChannelSftp sftpChannel = (ChannelSftp) channel;
|
|
|
159 |
for (Path path : paths) {
|
|
|
160 |
try {
|
|
|
161 |
sftpChannel.lstat(path.toString()); // if dir not exists an exception is thrown
|
|
|
162 |
}catch (SftpException e) {
|
|
|
163 |
throw new SSHManagerException(path.toString()+" does not exists!" +e.getLocalizedMessage());
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
}
|
124 |
}
|
167 |
}
|