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);
}
}
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()));
}
}
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()));
}
}
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()));
}
}
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;
}
Aggregations