Search in sources :

Example 51 with SftpException

use of com.jcraft.jsch.SftpException in project linuxtools by eclipse.

the class SSHFileStore method fetchInfo.

@Override
public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        monitor.beginTask(Messages.SSHFileStore_attrMonitor, 100);
        ChannelSftp channel = proxy.getChannelSftp();
        monitor.worked(25);
        SftpATTRS attrs = channel.stat(uri.getPath());
        monitor.worked(100);
        monitor.done();
        return createFileInfo(attrs);
    } catch (SftpException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SSHFileStore_attrFailed + e.getMessage()));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ChannelSftp(com.jcraft.jsch.ChannelSftp) CoreException(org.eclipse.core.runtime.CoreException) SftpATTRS(com.jcraft.jsch.SftpATTRS) SftpException(com.jcraft.jsch.SftpException)

Example 52 with SftpException

use of com.jcraft.jsch.SftpException in project linuxtools by eclipse.

the class SSHFileStore method childStores.

@Override
public IFileStore[] childStores(int options, IProgressMonitor monitor) throws CoreException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        monitor.beginTask(Messages.SSHFileStore_childStoresMonitor, 100);
        ChannelSftp channel = proxy.getChannelSftp();
        monitor.worked(25);
        Vector<?> v = channel.ls(uri.getPath());
        monitor.worked(50);
        LinkedList<IFileStore> childs = new LinkedList<>();
        boolean isDir = false;
        for (int i = 0; i < v.size(); i++) {
            ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) v.get(i);
            if (// $NON-NLS-1$ //$NON-NLS-2$
            !entry.getFilename().equals(".") && !entry.getFilename().equals(".."))
                childs.add(createFileStore(path.append(entry.getFilename()).toString()));
            else
                isDir = true;
        }
        if (!isDir)
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.SSHFileStore_childStoresFailedDirectory, getName())));
        monitor.worked(100);
        monitor.done();
        return childs.toArray(new IFileStore[0]);
    } catch (SftpException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SSHFileStore_childStoresFailed + e.getMessage()));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SftpException(com.jcraft.jsch.SftpException) LinkedList(java.util.LinkedList) ChannelSftp(com.jcraft.jsch.ChannelSftp) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 53 with SftpException

use of com.jcraft.jsch.SftpException in project linuxtools by eclipse.

the class SSHFileStore method childInfos.

@Override
public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    try {
        monitor.beginTask(Messages.SSHFileStore_childInfoMonitor, 100);
        ChannelSftp channel = proxy.getChannelSftp();
        monitor.worked(25);
        Vector<?> v = channel.ls(uri.getPath());
        monitor.worked(50);
        LinkedList<IFileInfo> childs = new LinkedList<>();
        boolean isDir = false;
        for (int i = 0; i < v.size(); i++) {
            ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) v.get(i);
            if (!entry.getFilename().equals(".") && !entry.getFilename().equals("..")) {
                // $NON-NLS-1$ //$NON-NLS-2$
                childs.add(createFileInfo(entry.getAttrs()));
            } else {
                isDir = true;
            }
        }
        if (!isDir) {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.SSHFileStore_childInfoFailedDirectory, getName())));
        }
        monitor.worked(100);
        monitor.done();
        return childs.toArray(new IFileInfo[0]);
    } catch (SftpException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SSHFileStore_childInfoFailed + e.getMessage()));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SftpException(com.jcraft.jsch.SftpException) LinkedList(java.util.LinkedList) ChannelSftp(com.jcraft.jsch.ChannelSftp) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException)

Example 54 with SftpException

use of com.jcraft.jsch.SftpException in project linuxtools by eclipse.

the class SSHFileStore method childNames.

@Override
public String[] childNames(int options, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    try {
        monitor.beginTask(Messages.SSHFileStore_childNamesMonitor, 100);
        ChannelSftp channel = proxy.getChannelSftp();
        monitor.worked(25);
        Vector<?> v = channel.ls(uri.getPath());
        monitor.worked(50);
        LinkedList<String> childs = new LinkedList<>();
        boolean isDir = false;
        for (int i = 0; i < v.size(); i++) {
            ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) v.get(i);
            if (!entry.getFilename().equals(".") && !entry.getFilename().equals("..")) {
                // $NON-NLS-1$ //$NON-NLS-2$
                childs.add(entry.getFilename());
            } else {
                isDir = true;
            }
        }
        if (!isDir) {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.SSHFileStore_childNamesFailedDirectory, getName())));
        }
        monitor.worked(100);
        monitor.done();
        return childs.toArray(new String[0]);
    } catch (SftpException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SSHFileStore_childNamesFailed + e.getMessage()));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SftpException(com.jcraft.jsch.SftpException) LinkedList(java.util.LinkedList) ChannelSftp(com.jcraft.jsch.ChannelSftp) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

SftpException (com.jcraft.jsch.SftpException)54 ChannelSftp (com.jcraft.jsch.ChannelSftp)26 IOException (java.io.IOException)18 Path (org.apache.hadoop.fs.Path)14 File (java.io.File)13 SftpATTRS (com.jcraft.jsch.SftpATTRS)9 GenericFileOperationFailedException (org.apache.camel.component.file.GenericFileOperationFailedException)9 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)8 JSchException (com.jcraft.jsch.JSchException)8 FileStatus (org.apache.hadoop.fs.FileStatus)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 Session (com.jcraft.jsch.Session)7 FileNotFoundException (java.io.FileNotFoundException)7 CoreException (org.eclipse.core.runtime.CoreException)7 IStatus (org.eclipse.core.runtime.IStatus)7 Status (org.eclipse.core.runtime.Status)7 Channel (com.jcraft.jsch.Channel)5 OutputStream (java.io.OutputStream)5 ArrayList (java.util.ArrayList)5 Vector (java.util.Vector)5