Search in sources :

Example 1 with IRemoteFile

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()]);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IRemoteFile(org.eclipse.ecf.filetransfer.IRemoteFile) Session(com.jcraft.jsch.Session)

Example 2 with IRemoteFile

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;
        }
    };
}
Also used : IRemoteFileSystemBrowseEvent(org.eclipse.ecf.filetransfer.events.IRemoteFileSystemBrowseEvent) IRemoteFile(org.eclipse.ecf.filetransfer.IRemoteFile) List(java.util.List)

Example 3 with IRemoteFile

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);
        }
    }
}
Also used : IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) IRemoteFileInfo(org.eclipse.ecf.filetransfer.IRemoteFileInfo) IRemoteFile(org.eclipse.ecf.filetransfer.IRemoteFile) Iterator(java.util.Iterator) IRemoteFileAttributes(org.eclipse.ecf.filetransfer.IRemoteFileAttributes) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with IRemoteFile

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");
}
Also used : BrowseFileTransferException(org.eclipse.ecf.filetransfer.BrowseFileTransferException) UnknownHostException(java.net.UnknownHostException) IRemoteFileSystemBrowseEvent(org.eclipse.ecf.filetransfer.events.IRemoteFileSystemBrowseEvent) IRemoteFile(org.eclipse.ecf.filetransfer.IRemoteFile) URL(java.net.URL) BrowseFileTransferException(org.eclipse.ecf.filetransfer.BrowseFileTransferException) UnknownHostException(java.net.UnknownHostException)

Example 5 with IRemoteFile

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);
        }
    }
}
Also used : IRemoteFileSystemBrowseEvent(org.eclipse.ecf.filetransfer.events.IRemoteFileSystemBrowseEvent) Iterator(java.util.Iterator) IRemoteFile(org.eclipse.ecf.filetransfer.IRemoteFile)

Aggregations

IRemoteFile (org.eclipse.ecf.filetransfer.IRemoteFile)6 Iterator (java.util.Iterator)3 IRemoteFileSystemBrowseEvent (org.eclipse.ecf.filetransfer.events.IRemoteFileSystemBrowseEvent)3 IRemoteFileAttributes (org.eclipse.ecf.filetransfer.IRemoteFileAttributes)2 IRemoteFileInfo (org.eclipse.ecf.filetransfer.IRemoteFileInfo)2 IFileID (org.eclipse.ecf.filetransfer.identity.IFileID)2 Session (com.jcraft.jsch.Session)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 List (java.util.List)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 BrowseFileTransferException (org.eclipse.ecf.filetransfer.BrowseFileTransferException)1