use of org.eclipse.ecf.filetransfer.IRemoteFile in project ecf by eclipse.
the class ScpFileSystemBrowser method runRequest.
/**
* Method called from super class to build the list of remote files.
*/
protected void runRequest() throws Exception {
scpUtil = new ScpUtil(this);
final Session s = scpUtil.getSession();
s.connect();
if (s.isConnected()) {
final String targetFileName = scpUtil.trimTargetFile(directoryOrFile.getPath());
final String command = LS_START_COMMAND + targetFileName + LS_END_COMMAND;
channel = (ChannelExec) s.openChannel(SCP_EXEC);
channel.setCommand(command);
final OutputStream outs = channel.getOutputStream();
inputStream = channel.getInputStream();
channel.connect();
setOutputStream(outs);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line = reader.readLine();
ArrayList strings = new ArrayList();
while (line != null) {
strings.add(line);
line = reader.readLine();
}
List remoteFilesList = new ArrayList();
for (int i = 0; i < strings.size(); i++) {
try {
remoteFilesList.add(createRemoteFile((String) strings.get(i)));
} catch (Exception e) {
Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "SCPFileBrowser could not convert string '" + ((String) strings.get(i)) + "' to FileID", // $NON-NLS-1$
e));
}
}
remoteFiles = (IRemoteFile[]) remoteFilesList.toArray(new IRemoteFile[remoteFilesList.size()]);
}
}
use of org.eclipse.ecf.filetransfer.IRemoteFile in project ecf by eclipse.
the class AbstractFileSystemBrowser method createRemoteFileEvent.
/**
* @return file system directory event
*/
protected IRemoteFileSystemEvent createRemoteFileEvent() {
return new IRemoteFileSystemBrowseEvent() {
public IFileID getFileID() {
return fileID;
}
public Exception getException() {
return exception;
}
public String toString() {
// $NON-NLS-1$
StringBuffer buf = new StringBuffer("RemoteFileSystemBrowseEvent[");
// $NON-NLS-1$ //$NON-NLS-2$
buf.append("fileID=").append(fileID).append(";");
List list = (remoteFiles != null) ? Arrays.asList(remoteFiles) : null;
// $NON-NLS-1$ //$NON-NLS-2$
buf.append("files=").append(list).append("]");
return buf.toString();
}
public IRemoteFile[] getRemoteFiles() {
return remoteFiles;
}
};
}
use of org.eclipse.ecf.filetransfer.IRemoteFile in project ecf by eclipse.
the class AbstractBrowseTestCase method verifyRemoteFiles.
/**
* @param remoteFiles
*/
protected void verifyRemoteFiles(final IRemoteFile[] remoteFiles) {
for (int i = 0; i < remoteFiles.length; i++) {
final IRemoteFile first = remoteFiles[i];
final IRemoteFileInfo firstInfo = first.getInfo();
assertNotNull(firstInfo);
final IFileID firstID = first.getID();
assertNotNull(firstID);
trace("firstID=" + firstID);
// Now check out info
assertNotNull(firstInfo.getName());
assertTrue(firstInfo.getLastModified() > 0);
trace("lastModified=" + new SimpleDateFormat().format(new Date(firstInfo.getLastModified())));
trace("length=" + firstInfo.getLength());
trace("isDirectory=" + firstInfo.isDirectory());
final IRemoteFileAttributes attributes = firstInfo.getAttributes();
assertNotNull(attributes);
final Iterator attrNames = attributes.getAttributeKeys();
for (; attrNames.hasNext(); ) {
final String key = (String) attrNames.next();
String s = "attrname=" + key;
s += " attrvalue=" + attributes.getAttribute(key);
trace(s);
}
}
}
use of org.eclipse.ecf.filetransfer.IRemoteFile in project ecf by eclipse.
the class URLBrowseTest method testBrowseUnknownHost.
public void testBrowseUnknownHost() throws Exception {
testBrowse(new URL(URLRetrieveTestUnknownHost.HTTP_UNKNOWN_HOST_URL));
Thread.sleep(3000);
assertHasEventCount(events, IRemoteFileSystemBrowseEvent.class, 1);
IRemoteFileSystemBrowseEvent event = (IRemoteFileSystemBrowseEvent) events.get(0);
assertNotNull(event);
final IRemoteFile[] remoteFiles = event.getRemoteFiles();
assertNull(remoteFiles);
Exception e = event.getException();
assertNotNull(e);
if (e instanceof BrowseFileTransferException) {
BrowseFileTransferException ifte = (BrowseFileTransferException) e;
assertTrue(ifte.getCause() instanceof UnknownHostException);
} else
fail("Event exception is not instance of BrowseFileTransferException");
}
use of org.eclipse.ecf.filetransfer.IRemoteFile in project ecf by eclipse.
the class URLBrowseTest method testBrowseURLs.
public void testBrowseURLs() throws Exception {
for (int i = 0; i < testURLs.length; i++) {
testBrowse(testURLs[i]);
Thread.sleep(10000);
}
assertHasEventCount(events, IRemoteFileSystemBrowseEvent.class, 3);
for (Iterator iterator = events.iterator(); iterator.hasNext(); ) {
IRemoteFileSystemBrowseEvent event = (IRemoteFileSystemBrowseEvent) iterator.next();
assertNotNull(event);
final IRemoteFile[] remoteFiles = event.getRemoteFiles();
assertNotNull(remoteFiles);
assertEquals(1, remoteFiles.length);
if (event.getFileID().getName().equals("http://google.com:80")) {
verifyRemoteFilesWithoutLastModifiedAndContentLength(remoteFiles);
} else {
verifyRemoteFiles(remoteFiles);
}
}
}
Aggregations