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