当前位置: 首页>>代码示例>>Java>>正文


Java ChannelSftp.rm方法代码示例

本文整理汇总了Java中com.jcraft.jsch.ChannelSftp.rm方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelSftp.rm方法的具体用法?Java ChannelSftp.rm怎么用?Java ChannelSftp.rm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jcraft.jsch.ChannelSftp的用法示例。


在下文中一共展示了ChannelSftp.rm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: delete

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
private void delete(String path, ChannelSftp c) throws Exception {
	String sessionLocalPath = extractSessionPath(path);
	try {
		if (c.stat(sessionLocalPath).isDir())
		{
			List<FileEntry> contents = listFiles(path, c);
			for (FileEntry fe: contents)
			{
				delete(fe.path, c);
			}
			c.rmdir(sessionLocalPath);
		}
		else
		{
			c.rm(sessionLocalPath);
		}
	} catch (Exception e) {
		tryDisconnect(c);
		throw convertException(e);
	}
	
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:23,代码来源:SftpStorage.java

示例2: rm

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
public static void rm(String user, String password, String addr, int port, List<String> fileName) throws JSchException, SftpException, Exception {
	
	if (fileName==null || fileName.size()<1) {
		return;
	}
	Session session = getSession(user, password, addr, port);				
	Channel channel = session.openChannel("sftp");
	channel.connect();
	ChannelSftp sftpChannel = (ChannelSftp) channel;		
	try {
		for (String f : fileName) {
			sftpChannel.rm(f);				
			logger.warn("success remove file from " + addr + " :" + fileName);				
		}
	} catch (Exception e) {
		e.printStackTrace();
		throw e;
	} finally {
		sftpChannel.exit();
		channel.disconnect();
		session.disconnect();				
	}		
}
 
开发者ID:billchen198318,项目名称:bamboobsc,代码行数:24,代码来源:SFtpClientUtils.java

示例3: delete

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
public boolean delete(String relativePath, boolean closeSession) {
	ChannelSftp sftp = null;
    try {
        // Get a reusable channel if the session is not auto closed.
        sftp = (closeSession) ? openConnectedChannel() : openConnectedChannel(CHANNEL_1);
        sftp.cd(basePath);
        sftp.rm(relativePath);
        return true;
    } catch (Exception e) {
        return false;
    } finally {
        if (closeSession) {
            close();
        }
    }
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:18,代码来源:SftpDirectory.java

示例4: doPostOperations

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
private void doPostOperations(ChannelSftp channel, String org) throws SftpException {
    if (StringUtils.isNotBlank(postMove)) {
        if (log.isDebugEnabled()) {
            log.debug("Sft post moving from '" + org + "' to '" + postMove + "'");
        }
        channel.rename(org, postMove);
    }
    if (postDelete) {
        if (log.isDebugEnabled()) {
            log.debug("Sft post deleting: " + org);
        }
        channel.rm(org);
    }
}
 
开发者ID:niuxuetao,项目名称:paxml,代码行数:15,代码来源:SftpTag.java

示例5: traverse

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
/**
 * Delete directory and its content recursively.
 * 
 * @param channel
 *            open channel to SFTP server
 * @param path
 *            path of the directory
 * @throws SftpException
 *             when something went wrong
 */
@SuppressWarnings("unchecked")
private void traverse(ChannelSftp channel, String path)
        throws SftpException {
    SftpATTRS attrs = channel.stat(path);
    if (attrs.isDir()) {
        Vector<LsEntry> files = channel.ls(path);
        if (files != null && files.size() > 0) {
            Iterator<LsEntry> it = files.iterator();
            while (it.hasNext()) {
                LsEntry entry = it.next();
                if ((!entry.getFilename().equals(".")) && (!entry.getFilename().equals(".."))) {
                    traverse(channel, path + "/" + entry.getFilename());
                }
            }
        }
        channel.rmdir(path);
    } else {
        channel.rm(path);
    }
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:31,代码来源:SftpDataStorageClient.java

示例6: delete

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
public boolean delete(Path path) throws IOException {
  ChannelSftp channel = null;
  try {
    channel = fsHelper.getSftpChannel();
    if (getFileStatus(path).isDir()) {
      channel.rmdir(path.toString());
    } else {
      channel.rm(path.toString());
    }
  } catch (SftpException e) {
    throw new IOException(e);
  } finally {
    safeDisconnect(channel);
  }
  return true;
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:18,代码来源:SftpLightWeightFileSystem.java

示例7: delFile

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
/**
    * 删除服务器上的文件
    * @param filepath
    * @return boolean
    */
   public  boolean delFile(String filepath) {
	boolean flag=false;
	ChannelSftp channel=getChannel();
	try {
		channel.rm(filepath);
		log.info("删除文件"+filepath+"成功");
		flag=true;
	} catch (SftpException e) {
		log.error("删除文件"+filepath+"失败");
		log.error(e.getMessage());
	}finally {
			//channel.quit();
          
       }
	
	return flag;
}
 
开发者ID:sapientTest,项目名称:Sapient,代码行数:23,代码来源:SftpFileUtil.java

示例8: _testConnectionSftp

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
private void _testConnectionSftp(String user, String password, String host, int port, IMoverInterface callbackContext) {
    try {
        JSch jsch = new JSch();

        Session session = jsch.getSession(user, host, port);
        session.setPassword(password);
        session.setConfig("StrictHostKeyChecking", "no");
        session.connect();

        ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
        channel.connect();

        OutputStream output = channel.put(mTestFilename);
        output.write("Hello Alto".getBytes());
        output.close();

        channel.rm(mTestFilename);
        channel.disconnect();

        session.disconnect();

        callbackContext.success();
    } catch (Exception e) {
        callbackContext.error(e.getMessage());
    }
}
 
开发者ID:adamduren,项目名称:cordova-mover,代码行数:27,代码来源:BaseMover.java

示例9: recursiveDelete

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
private static void recursiveDelete(ChannelSftp sftp, String path)
		throws SftpException, JSchException {
	Vector<?> entries = sftp.ls(path);
	for (Object object : entries) {
		LsEntry entry = (LsEntry) object;
		if (entry.getFilename().equals(".")
				|| entry.getFilename().equals("..")) {
			continue;
		}
		if (entry.getAttrs().isDir()) {
			recursiveDelete(sftp, path + entry.getFilename() + "/");
		} else {
			sftp.rm(path + entry.getFilename());
		}
	}
	sftp.rmdir(path);
}
 
开发者ID:apache,项目名称:incubator-taverna-common-activities,代码行数:18,代码来源:SshToolInvocation.java

示例10: doDelete

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
/**
 * Deletes the file.
 */
@Override
protected void doDelete() throws Exception
{
    final ChannelSftp channel = fileSystem.getChannel();
    try
    {
        if (getType() == FileType.FILE)
        {
            channel.rm(relPath);
        }
        else
        {
            channel.rmdir(relPath);
        }
    }
    finally
    {
        fileSystem.putChannel(channel);
    }
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:24,代码来源:SftpFileObject.java

示例11: delete

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:18,代码来源:SftpLightWeightFileSystem.java

示例12: prepareUpload

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
public boolean prepareUpload(
  ChannelSftp sftpChannel,
  String path,
  boolean overwrite)
  throws SftpException, IOException, FileNotFoundException {

  boolean result = false;

  // Build romote path subfolders inclusive:
  String[] folders = path.split("/");
  for (String folder : folders) {
    if (folder.length() > 0) {
      // This is a valid folder:
      try {
		    System.out.println("Current Folder path before cd:" + folder);
        sftpChannel.cd(folder);
      } catch (SftpException e) {
        // No such folder yet:
				System.out.println("Inside create folders: ");
        sftpChannel.mkdir(folder);
        sftpChannel.cd(folder);
      }
    }
  }

  // Folders ready. Remove such a file if exists:
  if (sftpChannel.ls(path).size() > 0) {
    if (!overwrite) {
      System.out.println(
        "Error - file " + path + " was not created on server. " +
        "It already exists and overwriting is forbidden.");
    } else {
      // Delete file:
      sftpChannel.ls(path); // Search file.
      sftpChannel.rm(path); // Remove file.
      result = true;
    }
  } else {
    // No such file:
    result = true;
  }

  return result;
}
 
开发者ID:jenkinsci,项目名称:ssh2easy-plugin,代码行数:45,代码来源:DefaultSshClient.java

示例13: processCommands

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
private Object processCommands(ChannelSftp channel) throws Exception {
    Object result = null;
    if ("get".equals(action)) {
        if (log.isDebugEnabled()) {
            log.debug("Sftp get from '" + from + "' to '" + to + "'");
        }
        ensureFrom();
        if (StringUtils.isBlank(to)) {
            // return content as result
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            channel.get(from, out);
            result = out.toString("UTF-8");
        } else {
            channel.get(from, to);
        }
        doPostOperations(channel, from);
    } else if ("put".equals(action)) {
        if (log.isDebugEnabled()) {
            log.debug("Sftp put from '" + from + "' to '" + to + "'");
        }
        ensureTo();
        if (StringUtils.isBlank(from)) {
            // put value as content
            Object val = getValue();
            if (val == null) {
                throw new PaxmlRuntimeException("Sftp command wrong: no value to put on remote server");
            }
            InputStream in = new ByteArrayInputStream(String.valueOf(val).getBytes("UTF-8"));
            channel.put(in, to);
        } else {
            channel.put(from, to);
        }
        doPostOperations(channel, to);
    } else if ("move".equals(action)) {
        if (log.isDebugEnabled()) {
            log.debug("Sftp move from '" + from + "' to '" + to + "'");
        }
        ensureFrom();
        ensureTo();
        channel.rename(from, to);
    } else if ("delete".equals(action)) {
        if (log.isDebugEnabled()) {
            log.debug("Sftp delete from: " + from);
        }
        ensureFrom();
        channel.rm(from);
    } else if ("mkdir".equals(action)) {
        if (log.isDebugEnabled()) {
            log.debug("Sftp mkdir to: " + to);
        }
        ensureTo();
        channel.mkdir(to);
    } else if ("list".equals(action)) {
        if (log.isDebugEnabled()) {
            log.debug("Sftp list from: " + from);
        }
        ensureFrom();
        result = channel.ls(from);
    } else {
        throw new PaxmlRuntimeException("Unknown sftp action: " + action);
    }

    return result;
}
 
开发者ID:niuxuetao,项目名称:paxml,代码行数:65,代码来源:SftpTag.java

示例14: openNextExportFile

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
Pair<BufferedReader,Runnable> openNextExportFile() throws Exception
{
    if (m_exportFiles.isEmpty())
    {
        checkForMoreExportFiles();
    }
    Pair<ChannelSftp, String> remotePair = m_exportFiles.poll();
    if (remotePair == null) return null;
    final ChannelSftp channel = remotePair.getFirst();
    final String path = remotePair.getSecond();
    System.out.println(
            "INFO export: Opening export file: " + channel.getSession().getHost() + "@" + path);
    final BufferedReader reader = new BufferedReader(
            new InputStreamReader(channel.get(path)), 4096 * 32
            );
    Runnable r = new Runnable()
    {
        @Override
        public void run()
        {
            try
            {
                reader.close();
                channel.rm(path);
            } catch (Exception e)
            {
                Throwables.propagate(e);
            }
        }
    };

    return Pair.of(reader,r);
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:34,代码来源:ExportOnServerVerifier.java

示例15: execute

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
protected void execute() throws SftpResult, JSchException {
    ChannelSftp ch = channel();
    try {
        ch.rm(path);
        throw new SftpResult(true);
    } catch (SftpException e) {
        if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
            throw new SftpResult(false);
        }
        throw new SftpError(e, "Error putting file[%s]", path);
    } finally {
        release(ch);
    }
}
 
开发者ID:osglworks,项目名称:java-sftp,代码行数:16,代码来源:Delete.java


注:本文中的com.jcraft.jsch.ChannelSftp.rm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。