Search in sources :

Example 41 with ChannelSftp

use of com.jcraft.jsch.ChannelSftp 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)

Example 42 with ChannelSftp

use of com.jcraft.jsch.ChannelSftp in project suite by stupidsing.

the class Ssh method channelSftp.

private <T> T channelSftp(Session session, SshFun<ChannelSftp, T> fun) throws IOException, SftpException, JSchException {
    ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
    channel.connect();
    try {
        return fun.apply(channel);
    } finally {
        channel.disconnect();
    }
}
Also used : ChannelSftp(com.jcraft.jsch.ChannelSftp)

Aggregations

ChannelSftp (com.jcraft.jsch.ChannelSftp)42 SftpException (com.jcraft.jsch.SftpException)24 IOException (java.io.IOException)15 JSchException (com.jcraft.jsch.JSchException)12 Session (com.jcraft.jsch.Session)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 File (java.io.File)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)6 JSch (com.jcraft.jsch.JSch)6 Path (org.apache.hadoop.fs.Path)6 InputStream (java.io.InputStream)5 SftpATTRS (com.jcraft.jsch.SftpATTRS)4 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 LinkedList (java.util.LinkedList)3 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)2 OutputStream (java.io.OutputStream)2