Search in sources :

Example 16 with ChannelSftp

use of com.jcraft.jsch.ChannelSftp in project gradle by gradle.

the class SftpResourceUploader method upload.

@Override
public void upload(ReadableContent resource, URI destination) throws IOException {
    LockableSftpClient client = sftpClientFactory.createSftpClient(destination, credentials);
    try {
        ChannelSftp channel = client.getSftpClient();
        ensureParentDirectoryExists(channel, destination);
        InputStream sourceStream = resource.open();
        try {
            channel.put(sourceStream, destination.getPath());
        } finally {
            sourceStream.close();
        }
    } catch (com.jcraft.jsch.SftpException e) {
        throw ResourceExceptions.putFailed(destination, e);
    } finally {
        sftpClientFactory.releaseSftpClient(client);
    }
}
Also used : ChannelSftp(com.jcraft.jsch.ChannelSftp) InputStream(java.io.InputStream)

Example 17 with ChannelSftp

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

the class SSHFileStore method delete.

@Override
public void delete(int options, IProgressMonitor monitor) throws CoreException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        monitor.beginTask(Messages.SSHFileStore_rmMonitor, 100);
        ChannelSftp channel = proxy.getChannelSftp();
        monitor.worked(25);
        if (channel.lstat(uri.getPath()).isDir())
            channel.rmdir(uri.getPath());
        else
            channel.rm(uri.getPath());
        monitor.worked(100);
        monitor.done();
    } catch (SftpException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SSHFileStore_rmFailed + 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) SftpException(com.jcraft.jsch.SftpException)

Example 18 with ChannelSftp

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

the class SSHFileStore method putInfo.

@Override
public void putInfo(IFileInfo info, int options, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    try {
        monitor.beginTask(Messages.SSHFileStore_putInfoMonitor, 100);
        ChannelSftp channel = proxy.getChannelSftp();
        monitor.worked(25);
        SftpATTRS attrs = channel.stat(uri.getPath());
        updateSftpATTRS(info);
        channel.setStat(uri.getPath(), attrs);
        monitor.worked(100);
        monitor.done();
    } catch (SftpException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SSHFileStore_putInfoFailed + 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 19 with ChannelSftp

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

the class SSHFileStore method openOutputStream.

@Override
public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException {
    try {
        ChannelSftp channel = proxy.getChannelSftp();
        int mode = ChannelSftp.OVERWRITE;
        if ((options & EFS.APPEND) != 0)
            mode = ChannelSftp.APPEND;
        return channel.put(uri.getPath(), new ProgressMonitor(monitor, Messages.SSHFileStore_getOutputStreamMonitor), mode);
    } catch (SftpException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SSHFileStore_getOutputStreamFailed + e.getMessage()));
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ChannelSftp(com.jcraft.jsch.ChannelSftp) CoreException(org.eclipse.core.runtime.CoreException) SftpException(com.jcraft.jsch.SftpException)

Example 20 with ChannelSftp

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

the class SSHFileStore method mkdir.

@Override
public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    monitor.beginTask(Messages.SSHFileStore_mkdirMonitor, 100);
    ChannelSftp channel = proxy.getChannelSftp();
    monitor.worked(25);
    IPath new_path = Path.ROOT;
    if ((options & EFS.SHALLOW) == 0) {
        for (String segment : path.segments()) {
            new_path = new_path.append(segment);
            try {
                channel.stat(new_path.toString());
            } catch (SftpException e) {
                // Path doesn't exist
                createDir(channel, new_path.toString());
            }
        }
    } else
        createDir(channel, uri.getPath());
    monitor.worked(100);
    monitor.done();
    return this;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ChannelSftp(com.jcraft.jsch.ChannelSftp) IPath(org.eclipse.core.runtime.IPath) SftpException(com.jcraft.jsch.SftpException)

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