本文整理匯總了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();
}
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}