use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.
the class SftpServiceImpl method changeGroup.
@Override
public void changeGroup(FileChangeGroupRequest request) {
String path = Files1.getPath(request.getPath());
SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
synchronized (executor) {
executor.chgrp(path, request.getGid());
}
// 设置日志参数
EventParamsHolder.addParams(request);
}
use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.
the class SftpServiceImpl method chown.
@Override
public void chown(FileChownRequest request) {
String path = Files1.getPath(request.getPath());
SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
synchronized (executor) {
executor.chown(path, request.getUid());
}
// 设置日志参数
EventParamsHolder.addParams(request);
}
use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.
the class SftpServiceImpl method remove.
@Override
public void remove(FileRemoveRequest request) {
SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
List<String> paths = request.getPaths();
synchronized (executor) {
paths.stream().map(Files1::getPath).forEach(executor::rm);
}
// 设置日志参数
EventParamsHolder.addParams(request);
EventParamsHolder.addParam(EventKeys.COUNT, paths.size());
}
use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.
the class SftpServiceImpl method mkdir.
@Override
public String mkdir(FileMkdirRequest request) {
String path = Files1.getPath(request.getPath());
SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
synchronized (executor) {
executor.mkdirs(path);
}
// 设置日志参数
EventParamsHolder.addParams(request);
return path;
}
use of com.orion.remote.channel.sftp.SftpExecutor in project orion-ops by lijiahangmax.
the class SftpServiceImpl method download.
@Override
public void download(FileDownloadRequest request) {
// 获取token信息
Long machineId = this.getMachineId(request.getSessionToken());
SftpExecutor executor = sftpBasicExecutorHolder.getBasicExecutor(request.getSessionToken());
UserDTO user = Currents.getUser();
Long userId = user.getId();
// 定义文件转换器
Function<SftpFile, FileTransferLogDO> convert = file -> {
// 本地保存路径
String fileToken = ObjectIds.next();
// 设置传输信息
FileTransferLogDO download = new FileTransferLogDO();
download.setUserId(userId);
download.setUserName(user.getUsername());
download.setFileToken(fileToken);
download.setTransferType(SftpTransferType.DOWNLOAD.getType());
download.setMachineId(machineId);
download.setRemoteFile(file.getPath());
download.setLocalFile(PathBuilders.getSftpDownloadFilePath(fileToken));
download.setCurrentSize(0L);
download.setFileSize(file.getSize());
download.setNowProgress(0D);
download.setTransferStatus(SftpTransferStatus.WAIT.getStatus());
return download;
};
// 初始化下载信息
List<FileTransferLogDO> downloadFiles = Lists.newList();
List<String> paths = request.getPaths();
for (String path : paths) {
SftpFile file = executor.getFile(path);
Valid.notNull(file, Strings.format(MessageConst.FILE_NOT_FOUND, path));
// 如果是文件夹则递归所有文件
if (file.isDirectory()) {
List<SftpFile> childFiles = executor.listFiles(path, true, false);
childFiles.forEach(f -> downloadFiles.add(convert.apply(f)));
} else {
downloadFiles.add(convert.apply(file));
}
}
for (FileTransferLogDO downloadFile : downloadFiles) {
fileTransferLogDAO.insert(downloadFile);
// 通知添加
transferProcessorManager.notifySessionAddEvent(userId, machineId, downloadFile.getFileToken(), downloadFile);
}
// 提交下载任务
for (FileTransferLogDO downloadFile : downloadFiles) {
IFileTransferProcessor.of(FileTransferHint.transfer(downloadFile)).exec();
}
// 设置日志参数
EventParamsHolder.addParam(EventKeys.MACHINE_ID, machineId);
EventParamsHolder.addParam(EventKeys.PATHS, paths);
EventParamsHolder.addParam(EventKeys.COUNT, downloadFiles.size());
}
Aggregations