Search in sources :

Example 1 with SftpExecutor

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;
}
Also used : SessionStore(com.orion.remote.channel.SessionStore) SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor)

Example 2 with SftpExecutor

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();
}
Also used : SftpFile(com.orion.remote.channel.sftp.SftpFile) SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor) FileTransferLogDO(com.orion.ops.entity.domain.FileTransferLogDO) FileTransferNotifyDTO(com.orion.ops.entity.dto.FileTransferNotifyDTO) IFileTransferProcessor(com.orion.ops.handler.sftp.IFileTransferProcessor)

Example 3 with SftpExecutor

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;
}
Also used : SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor)

Example 4 with SftpExecutor

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;
}
Also used : SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor)

Example 5 with SftpExecutor

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;
    }
}
Also used : SftpFile(com.orion.remote.channel.sftp.SftpFile) SftpExecutor(com.orion.remote.channel.sftp.SftpExecutor) FileListVO(com.orion.ops.entity.vo.sftp.FileListVO) FileDetailVO(com.orion.ops.entity.vo.sftp.FileDetailVO)

Aggregations

SftpExecutor (com.orion.remote.channel.sftp.SftpExecutor)15 FileListVO (com.orion.ops.entity.vo.sftp.FileListVO)4 SftpFile (com.orion.remote.channel.sftp.SftpFile)4 Const (com.orion.ops.consts.Const)3 EventKeys (com.orion.ops.consts.event.EventKeys)3 EventParamsHolder (com.orion.ops.consts.event.EventParamsHolder)3 FileTransferLogDO (com.orion.ops.entity.domain.FileTransferLogDO)3 FileTransferNotifyDTO (com.orion.ops.entity.dto.FileTransferNotifyDTO)3 FileDetailVO (com.orion.ops.entity.vo.sftp.FileDetailVO)3 FileOpenVO (com.orion.ops.entity.vo.sftp.FileOpenVO)3 IFileTransferProcessor (com.orion.ops.handler.sftp.IFileTransferProcessor)3 MachineInfoService (com.orion.ops.service.api.MachineInfoService)3 SftpService (com.orion.ops.service.api.SftpService)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Resource (javax.annotation.Resource)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 ObjectIds (com.orion.id.ObjectIds)2 UUIds (com.orion.id.UUIds)2 KeyConst (com.orion.ops.consts.KeyConst)2