use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method downloadDir.
/**
* Recursively download directory from agent to local pc
*
* @param sf
* @param localFileName
* @throws IOException
* @throws NXCException
*/
private void downloadDir(final AgentFile sf, String localFileName, ZipOutputStream zos, final IProgressMonitor monitor, ConsoleJobCallingServerJob job) throws NXCException, IOException {
List<AgentFile> files = sf.getChildren();
if (files == null) {
files = session.listAgentFiles(sf, sf.getFullName(), sf.getNodeId());
sf.setChildren(files);
}
for (AgentFile f : files) {
if (job.isCanceled())
break;
if (f.isDirectory()) {
downloadDir(f, localFileName + "/" + f.getName(), zos, monitor, job);
} else {
monitor.subTask(String.format("Compressing file %s", f.getFullName()));
final AgentFileData file = session.downloadFileFromAgent(objectId, f.getFullName(), 0, false, new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, job);
if (file != null && file.getFile() != null) {
FileInputStream fis = new FileInputStream(file.getFile());
ZipEntry zipEntry = new ZipEntry(localFileName + "/" + f.getName());
zos.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zos.write(bytes, 0, length);
}
zos.closeEntry();
fis.close();
}
}
}
}
use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method uploadFile.
/**
* Upload local file to agent
*/
private void uploadFile(final boolean overvrite) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.isEmpty())
return;
final Object[] objects = selection.toArray();
final AgentFile upladFolder = ((AgentFile) objects[0]).isDirectory() ? ((AgentFile) objects[0]) : ((AgentFile) objects[0]).getParent();
final StartClientToServerFileUploadDialog dlg = new StartClientToServerFileUploadDialog(getSite().getShell());
if (dlg.open() == Window.OK) {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().AgentFileManager_UploadFileJobTitle, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
List<File> fileList = dlg.getLocalFiles();
for (int i = 0; i < fileList.size(); i++) {
final File localFile = fileList.get(i);
String remoteFile = fileList.get(i).getName();
if (fileList.size() == 1)
remoteFile = dlg.getRemoteFileName();
final String rFileName = remoteFile;
new NestedVerifyOverwrite(localFile.isDirectory() ? AgentFile.DIRECTORY : AgentFile.FILE, localFile.getName(), true, true, false) {
@Override
public void executeAction() throws NXCException, IOException {
session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName() + "/" + rFileName, overvrite, new // $NON-NLS-1$
ProgressListener() {
private long prevWorkDone = 0;
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask(Messages.get(getDisplay()).UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(), (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) (workDone - prevWorkDone));
prevWorkDone = workDone;
}
});
monitor.done();
}
@Override
public void executeSameFunctionWithOverwrite() throws IOException, NXCException {
session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName() + "/" + rFileName, true, new // $NON-NLS-1$
ProgressListener() {
private long prevWorkDone = 0;
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask(Messages.get(getDisplay()).UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(), (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) (workDone - prevWorkDone));
prevWorkDone = workDone;
}
});
monitor.done();
}
}.run(viewer.getControl().getDisplay());
}
upladFolder.setChildren(session.listAgentFiles(upladFolder, upladFolder.getFullName(), objectId));
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.refresh(upladFolder, true);
}
});
}
@Override
protected String getErrorMessage() {
return "Cannot upload file to remote agent";
}
}.start();
}
}
use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method copyFilePath.
/**
* Copy full path to file to clipboard
*/
private void copyFilePath() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() != 1)
return;
String filePath = ((AgentFile) selection.getFirstElement()).getFilePath();
JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
if (executor != null) {
StringBuilder js = new StringBuilder();
filePath = filePath.replace("\\", "\\\\");
// Substring is made to remove first "/"
js.append("copyTextToClipboard(\'" + filePath + "\');");
executor.execute(js.toString());
}
}
Aggregations