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


Java ChannelSftp.rename方法代码示例

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


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

示例1: renameFile

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
public boolean renameFile(String fromFilePath, String toFilePath, 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.rename(fromFilePath, toFilePath);
        return true;
    } catch (Exception e) {
        return false;
    } finally {
        if (closeSession) {
            close();
        }
    }
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:18,代码来源:SftpDirectory.java

示例2: moveToDir

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
public void moveToDir(String fromFilePath, String toDirPath, boolean closeSession) {
    ChannelSftp sftp = null;
    FileInfo fileInfo = new FileInfo(fromFilePath, false, new java.util.Date().getTime(), -1);
    try {
        // Get a reusable channel if the session is not auto closed.
        sftp = (closeSession) ? openConnectedChannel() : openConnectedChannel(CHANNEL_1);
        sftp.cd(basePath);
        if (!toDirPath.endsWith("/")) {
        	toDirPath += "/";
        }
        sftp.rename(fromFilePath, toDirPath + fileInfo.getName());
    } catch (Exception e) {
        throw new IoException("Error moving (renaming) directory.  Error %s", e.getMessage());
    } finally {
        if (closeSession) {
            close();
        }
    }
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:21,代码来源:SftpDirectory.java

示例3: moveFile

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
public void moveFile(String fromFilePath, String toFilePath, 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.rename(fromFilePath, toFilePath);
    } catch (Exception e) {
        throw new IoException("Error moving (renaming) file.  Error %s", e.getMessage());
    } finally {
        if (closeSession) {
            close();
        }
    }
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:17,代码来源:SftpDirectory.java

示例4: rename

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
/**
   * 文件重命名
   * @param oldpath
   * @param newpath
   * @return boolean
   */
  public  boolean rename(String oldpath,String newpath) {
	boolean flag=false;
	ChannelSftp channel=getChannel();
	try {
		channel.rename(oldpath, newpath);
		log.info("重命名文件"+oldpath+"成功");
		log.info("更新后的文件名为:"+newpath);
		flag=true;
	} catch (SftpException e) {
		log.error("重命名文件"+oldpath+"失败");
		log.error(e.getMessage());
	}finally {
		//channel.quit();
         
      }
	
	return flag;
}
 
开发者ID:sapientTest,项目名称:Sapient,代码行数:25,代码来源:SftpFileUtil.java

示例5: call

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
public StatInfo call() throws Exception {
    StatInfo result = null;
    SftpException exception = null;
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "{0} started", getTraceName());
    }
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(PREFIX + ": " + getTraceName()); // NOI18N
    RemoteStatistics.ActivityID activityID = RemoteStatistics.startChannelActivity("move", from); // NOI18N
    ChannelSftp cftp = null;
    try {
        cftp = getChannel();
        cftp.rename(from, to);
    } catch (SftpException e) {
        exception = e;
        if (e.id == SftpIOException.SSH_FX_FAILURE) {
            if (MiscUtils.mightBrokeSftpChannel(e)) {
                cftp.quit();
            }
        }
    } finally {
        RemoteStatistics.stopChannelActivity(activityID);
        releaseChannel(cftp);
        Thread.currentThread().setName(threadName);
    }
    if (exception != null) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.log(Level.FINE, "{0} failed", getTraceName());
        }
        throw decorateSftpException(exception, from + " to " + to); //NOI18N
    }

    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "{0} finished", new Object[] {getTraceName()});
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:SftpSupport.java

示例6: rename

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
public boolean rename(Path oldPath, Path newPath) throws IOException {
  ChannelSftp channelSftp = null;
  try {
    channelSftp = this.fsHelper.getSftpChannel();
    channelSftp.rename(HadoopUtils.toUriPath(oldPath), HadoopUtils.toUriPath(newPath));

  } catch (SftpException e) {
    throw new IOException(e);
  } finally {
    safeDisconnect(channelSftp);
  }
  return true;
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:15,代码来源:SftpLightWeightFileSystem.java

示例7: 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

示例8: rename

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
public boolean rename(Path oldpath, Path newpath) throws IOException {
  ChannelSftp channelSftp = null;
  try {
    channelSftp = fsHelper.getSftpChannel();
    channelSftp.rename(oldpath.toString(), newpath.toString());

  } catch (SftpException e) {
    throw new IOException(e);
  } finally {
    safeDisconnect(channelSftp);
  }
  return true;
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:15,代码来源:SftpLightWeightFileSystem.java

示例9: doRename

import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
/**
 * Rename the file.
 */
@Override
protected void doRename(FileObject newfile) throws Exception
{
    final ChannelSftp channel = fileSystem.getChannel();
    try
    {
        channel.rename(relPath, ((SftpFileObject) newfile).relPath);
    }
    finally
    {
        fileSystem.putChannel(channel);
    }
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:17,代码来源:SftpFileObject.java

示例10: execute

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

示例11: 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


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