use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.
the class SftpBasicExecutorHolder method getBasicExecutor.
/**
* 获取 sftp 基本操作 executor
*
* @param machineId machineId
* @return SftpExecutor
*/
public SftpExecutor getBasicExecutor(Long machineId) {
SftpExecutor executor = basicExecutorHolder.get(machineId);
if (executor != null) {
if (!executor.isConnected()) {
try {
executor.connect();
} catch (Exception e) {
// 无法连接则重新创建实例
executor = null;
}
}
}
// 如果没有重新建立连接
if (executor == null) {
// 获取charset
String charset = machineEnvService.getSftpCharset(machineId);
// 打开sftp连接
SessionStore sessionStore = machineInfoService.openSessionStore(machineId);
executor = sessionStore.getSftpExecutor(charset);
executor.connect();
basicExecutorHolder.put(machineId, executor);
}
executorUsing.put(machineId, System.currentTimeMillis());
return executor;
}
use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.
the class SftpServiceImpl method transferReTransfer.
/**
* 重新传输
*/
private void transferReTransfer(String fileToken, boolean isUpload) {
// 获取请求文件
FileTransferLogDO transferLog = this.getTransferLogByToken(fileToken);
Valid.notNull(transferLog, MessageConst.UNSELECTED_TRANSFER_LOG);
Long machineId = transferLog.getMachineId();
// 暂停
IFileTransferProcessor processor = transferProcessorManager.getProcessor(transferLog.getFileToken());
if (processor != null) {
processor.stop();
}
if (isUpload) {
// 删除远程文件
SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(machineId);
SftpFile file = executor.getFile(transferLog.getRemoteFile());
if (file != null) {
executor.rmFile(transferLog.getRemoteFile());
}
} else {
// 删除本地文件
String loacalPath = Files1.getPath(SystemEnvAttr.SWAP_PATH.getValue(), transferLog.getLocalFile());
Files1.delete(loacalPath);
}
// 修改进度
FileTransferLogDO update = new FileTransferLogDO();
update.setId(transferLog.getId());
update.setTransferStatus(SftpTransferStatus.WAIT.getStatus());
update.setNowProgress(0D);
update.setCurrentSize(0L);
fileTransferLogDAO.updateById(update);
// 通知进度
FileTransferNotifyDTO.FileTransferNotifyProgress progress = FileTransferNotifyDTO.progress(Strings.EMPTY, Files1.getSize(transferLog.getFileSize()), "0");
transferProcessorManager.notifySessionProgressEvent(transferLog.getUserId(), machineId, transferLog.getFileToken(), progress);
// 通知状态
transferProcessorManager.notifySessionStatusEvent(transferLog.getUserId(), machineId, transferLog.getFileToken(), SftpTransferStatus.WAIT.getStatus());
// 提交下载
IFileTransferProcessor.of(FileTransferHint.transfer(transferLog)).exec();
}
use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.
the class SftpServiceImpl method move.
@Override
public String move(FileMoveRequest request) {
String source = Files1.getPath(request.getSource());
String target = Files1.getPath(request.getTarget());
SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
synchronized (executor) {
executor.mv(source, target);
}
// 设置日志参数
EventParamsHolder.addParams(request);
return target;
}
use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.
the class SftpServiceImpl method touch.
@Override
public String touch(FileTouchRequest request) {
String path = Files1.getPath(request.getPath());
SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
synchronized (executor) {
executor.touch(path);
}
// 设置日志参数
EventParamsHolder.addParams(request);
return path;
}
use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.
the class SftpServiceImpl method listDir.
@Override
public FileListVO listDir(FileListRequest request) {
SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
synchronized (executor) {
String path = request.getPath();
List<SftpFile> fileList = executor.listDirs(path);
// 返回
FileListVO fileListVO = new FileListVO();
List<FileDetailVO> files = Converts.toList(fileList, FileDetailVO.class);
fileListVO.setPath(path);
fileListVO.setFiles(files);
return fileListVO;
}
}
Aggregations