Java Code Examples for com.jcraft.jsch.ChannelSftp#rmdir()
The following examples show how to use
com.jcraft.jsch.ChannelSftp#rmdir() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SshFileController.java From Jpom with MIT License | 8 votes |
/** * 删除文件或者文件夹 * * @param channel channel * @param path 文件路径 * @throws SftpException SftpException */ private void deleteFile(ChannelSftp channel, String path) throws SftpException { Vector<ChannelSftp.LsEntry> vector = channel.ls(path); if (null == vector) { return; } int size = vector.size(); if (size == 1) { // 文件,直接删除 channel.rm(path); } else if (size == 2) { // 空文件夹,直接删除 channel.rmdir(path); } else { // 删除文件夹下所有文件 String fileName; for (ChannelSftp.LsEntry en : vector) { fileName = en.getFilename(); if (!".".equals(fileName) && !"..".equals(fileName)) { deleteFile(channel, path + "/" + fileName); } } channel.rmdir(path); } }
Example 2
Source File: SFTPOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
private void delete(ChannelSftp channel, Info info, DeleteParameters params) throws IOException, SftpException { if (Thread.currentThread().isInterrupted()) { throw new IOException(FileOperationMessages.getString("IOperationHandler.interrupted")); //$NON-NLS-1$ } URI uri = info.getURI(); if (info.isDirectory()) { if (params.isRecursive()) { List<Info> children = list(uri, channel, LIST_NONRECURSIVE); for (Info child: children) { delete(channel, child, params); } channel.rmdir(getPath(uri)); } else { throw new IOException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.cannot_remove_directory"), uri)); //$NON-NLS-1$ } } else { channel.rm(getPath(uri)); } }
Example 3
Source File: PooledSFTPOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
private void delete(ChannelSftp channel, Info info, DeleteParameters params) throws IOException, SftpException { if (Thread.currentThread().isInterrupted()) { throw new IOException(FileOperationMessages.getString("IOperationHandler.interrupted")); //$NON-NLS-1$ } URI uri = info.getURI(); if (info.isDirectory()) { if (params.isRecursive()) { List<Info> children = list(uri, channel, LIST_NONRECURSIVE); for (Info child: children) { delete(channel, child, params); } channel.rmdir(getPath(uri)); } else { throw new IOException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.cannot_remove_directory"), uri)); //$NON-NLS-1$ } } else { channel.rm(getPath(uri)); } }
Example 4
Source File: SftpLightWeightFileSystem.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@Override public boolean delete(Path path) throws IOException { ChannelSftp channel = null; try { channel = this.fsHelper.getSftpChannel(); if (getFileStatus(path).isDirectory()) { channel.rmdir(HadoopUtils.toUriPath(path)); } else { channel.rm(HadoopUtils.toUriPath(path)); } } catch (SftpException e) { throw new IOException(e); } finally { safeDisconnect(channel); } return true; }
Example 5
Source File: SftpFileUtil.java From Leo with Apache License 2.0 | 6 votes |
/** * 删除指定目录,此目录必须为空的目录 * @param directory * @return boolean */ public boolean delDir(String directory) { boolean flag=false; ChannelSftp channel=getChannel(); try { channel.rmdir(directory); log.info("删除目录:"+directory+"成功"); flag=true; } catch (SftpException e) { log.error("删除目录:"+directory+"失败"); log.error(e.getMessage()); }finally { //channel.quit(); } return flag; }
Example 6
Source File: SftpFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Deletes the file. */ @Override protected void doDelete() throws Exception { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { if (isFile()) { channel.rm(relPath); } else { channel.rmdir(relPath); } } finally { getAbstractFileSystem().putChannel(channel); } }