throws InvocationTargetException, InterruptedException {
String guid = new VMID().toString().replace(':', '_');
monitor.beginTask("Secure Copy", 100);
scp(directory, "/tmp/hadoop_scp_" + guid,
new SubProgressMonitor(monitor, 60));
try {
SubProgressMonitor sub = new SubProgressMonitor(monitor, 1);
if (monitor.isCanceled()) {
return;
}
final File dir = new File(directory);
sub.beginTask("Move files from staging server to DFS", 1);
ChannelExec exec =
exec(" dfs " + s_whichFS
+ " -moveFromLocal /tmp/hadoop_scp_" + guid + " \""
+ getPath() + "/" + dir.getName() + "\"");
BufferedReader reader =
new BufferedReader(new InputStreamReader(
new BufferedInputStream(exec.getInputStream())));
if (!monitor.isCanceled()) {
exec.connect();
String line = reader.readLine();
sub.worked(1);
}
if (exec.isConnected()) {
exec.disconnect();
}
sub.done();
monitor.done();
doRefresh();
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
throw new InvocationTargetException(e);
}
}
public void scp(String from, String to, IProgressMonitor monitor) {
File file = new File(from);
ChannelExec channel = null;
monitor.beginTask("scp from " + from + " to " + to, 100 * (file
.isDirectory() ? file.list().length + 1 : 1));
if (monitor.isCanceled()) {
return;
}
if (file.isDirectory()) {
// mkdir
try {
channel = (ChannelExec) getSession().openChannel("exec");
channel.setCommand(" mkdir " + to);
InputStream in = channel.getInputStream();
channel.connect();
// in.read(); // wait for a response, which
// we'll then ignore
} catch (JSchException e) {
// BUG(jz) abort operation and display error
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (channel.isConnected()) {
channel.disconnect();
}
}
monitor.worked(100);
String[] children = file.list();
for (int i = 0; i < children.length; i++) {
File child = new File(file, children[i]);
// recurse
scp(new File(file, children[i]).getAbsolutePath(), to + "/"
+ children[i], new SubProgressMonitor(monitor, 100));
}
} else {
InputStream filein = null;
try {