🔨 下载文件.
This commit is contained in:
@@ -123,6 +123,14 @@ public enum InputTypeEnum {
|
||||
new String[]{"type", "sessionId", "path", "mod"},
|
||||
SftpChangeModRequest.class),
|
||||
|
||||
/**
|
||||
* SFTP 下载文件夹 flat
|
||||
*/
|
||||
SFTP_DOWNLOAD_DIRECTORY_FLAT("df",
|
||||
SftpDownloadDirectoryFlatHandler.class,
|
||||
new String[]{"type", "sessionId", "currentPath", "path"},
|
||||
SftpDownloadDirectoryFlatRequest.class),
|
||||
|
||||
/**
|
||||
* SFTP 获取内容
|
||||
*/
|
||||
@@ -139,10 +147,6 @@ public enum InputTypeEnum {
|
||||
new String[]{"type", "sessionId", "path", "content"},
|
||||
SftpSetContentRequest.class),
|
||||
|
||||
// TODO
|
||||
// UPLOAD
|
||||
// DOWNLOAD
|
||||
|
||||
;
|
||||
|
||||
private static final char SEPARATOR = '|';
|
||||
|
||||
@@ -75,6 +75,11 @@ public enum OutputTypeEnum {
|
||||
*/
|
||||
SFTP_CHMOD("cm", "${type}|${sessionId}|${result}|${msg}"),
|
||||
|
||||
/**
|
||||
* SFTP 下载文件夹 flat
|
||||
*/
|
||||
SFTP_DOWNLOAD_DIRECTORY_FLAT("df", "${type}|${sessionId}|${currentPath}|${body}"),
|
||||
|
||||
/**
|
||||
* SFTP 获取文件内容
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.orion.ops.module.asset.handler.host.terminal.handler;
|
||||
|
||||
import com.orion.ops.framework.common.enums.BooleanBit;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.enums.OutputTypeEnum;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.model.request.SftpDownloadDirectoryFlatRequest;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.model.response.SftpDownloadDirectoryFlatResponse;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.session.ISftpSession;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
/**
|
||||
* sftp 下载文件夹 flat
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/2/19 11:13
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SftpDownloadDirectoryFlatHandler extends AbstractTerminalHandler<SftpDownloadDirectoryFlatRequest> {
|
||||
|
||||
@Override
|
||||
public void handle(WebSocketSession channel, SftpDownloadDirectoryFlatRequest payload) {
|
||||
// 获取会话
|
||||
ISftpSession session = terminalManager.getSession(channel.getId(), payload.getSessionId());
|
||||
String path = payload.getPath();
|
||||
log.info("SftpDownloadDirectoryFlatHandler-handle session: {}, path: {}", payload.getSessionId(), path);
|
||||
Exception ex = null;
|
||||
// 获取文件夹内的全部文件
|
||||
try {
|
||||
// TODO
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("SftpDownloadDirectoryFlatHandler-handle error", e);
|
||||
ex = e;
|
||||
}
|
||||
// 返回
|
||||
this.send(channel,
|
||||
OutputTypeEnum.SFTP_DOWNLOAD_DIRECTORY_FLAT,
|
||||
SftpDownloadDirectoryFlatResponse.builder()
|
||||
.sessionId(payload.getSessionId())
|
||||
.currentPath(payload.getPath())
|
||||
// TODO
|
||||
.body("")
|
||||
.result(BooleanBit.of(ex == null).getValue())
|
||||
.msg(this.getErrorMessage(ex))
|
||||
.build());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -103,6 +103,7 @@ public class TerminalConnectHandler extends AbstractTerminalHandler<TerminalConn
|
||||
try {
|
||||
// 连接配置
|
||||
TerminalConfig config = TerminalConfig.builder()
|
||||
.hostId(connect.getHostId())
|
||||
.charset(connect.getCharset())
|
||||
.fileNameCharset(connect.getFileNameCharset())
|
||||
.fileContentCharset(connect.getFileContentCharset())
|
||||
|
||||
@@ -22,6 +22,9 @@ import lombok.NoArgsConstructor;
|
||||
@Schema(name = "TerminalConfig", description = "主机终端连接参数")
|
||||
public class TerminalConfig {
|
||||
|
||||
@Schema(description = "主机id")
|
||||
private Long hostId;
|
||||
|
||||
@Schema(description = "cols")
|
||||
private Integer cols;
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.orion.ops.module.asset.handler.host.terminal.model.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* sftp 下载文件夹 flat 实体对象
|
||||
* <p>
|
||||
* i|eff00a1|currentPath|path
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/2/6 13:31
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(name = "SftpDownloadDirectoryFlatRequest", description = "sftp 下载文件夹 flat 实体对象")
|
||||
public class SftpDownloadDirectoryFlatRequest extends SftpBaseRequest {
|
||||
|
||||
@Schema(description = "当前路径")
|
||||
private Integer currentPath;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.orion.ops.module.asset.handler.host.terminal.model.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* sftp 下载文件夹 flat 实体对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/2/6 16:20
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(name = "SftpDownloadDirectoryFlatResponse", description = "sftp 下载文件夹 flat 实体对象")
|
||||
public class SftpDownloadDirectoryFlatResponse extends SftpBaseResponse {
|
||||
|
||||
@Schema(description = "currentPath")
|
||||
private String currentPath;
|
||||
|
||||
@Schema(description = "body")
|
||||
private String body;
|
||||
|
||||
}
|
||||
@@ -32,8 +32,6 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public class SftpSession extends TerminalSession implements ISftpSession {
|
||||
|
||||
private final TerminalConfig config;
|
||||
|
||||
private final SessionStore sessionStore;
|
||||
|
||||
private SftpExecutor executor;
|
||||
@@ -42,9 +40,8 @@ public class SftpSession extends TerminalSession implements ISftpSession {
|
||||
WebSocketSession channel,
|
||||
SessionStore sessionStore,
|
||||
TerminalConfig config) {
|
||||
super(sessionId, channel);
|
||||
super(sessionId, channel, config);
|
||||
this.sessionStore = sessionStore;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,8 +9,8 @@ import com.orion.ops.module.asset.define.AssetThreadPools;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.constant.TerminalMessage;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.enums.OutputTypeEnum;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.model.TerminalConfig;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.model.response.TerminalCloseResponse;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.model.response.SshOutputResponse;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.model.response.TerminalCloseResponse;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
@@ -29,8 +29,6 @@ import java.io.InputStream;
|
||||
@Slf4j
|
||||
public class SshSession extends TerminalSession implements ISshSession {
|
||||
|
||||
private final TerminalConfig config;
|
||||
|
||||
private final SessionStore sessionStore;
|
||||
|
||||
private ShellExecutor executor;
|
||||
@@ -42,9 +40,8 @@ public class SshSession extends TerminalSession implements ISshSession {
|
||||
WebSocketSession channel,
|
||||
SessionStore sessionStore,
|
||||
TerminalConfig config) {
|
||||
super(sessionId, channel);
|
||||
super(sessionId, channel, config);
|
||||
this.sessionStore = sessionStore;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.orion.ops.module.asset.handler.host.terminal.session;
|
||||
|
||||
import com.orion.ops.module.asset.enums.HostConnectStatusEnum;
|
||||
import com.orion.ops.module.asset.handler.host.terminal.model.TerminalConfig;
|
||||
import com.orion.ops.module.asset.service.HostConnectLogService;
|
||||
import com.orion.spring.SpringHolder;
|
||||
import lombok.Getter;
|
||||
@@ -22,11 +23,14 @@ public abstract class TerminalSession implements ITerminalSession {
|
||||
|
||||
protected final WebSocketSession channel;
|
||||
|
||||
protected final TerminalConfig config;
|
||||
|
||||
protected volatile boolean close;
|
||||
|
||||
public TerminalSession(String sessionId, WebSocketSession channel) {
|
||||
public TerminalSession(String sessionId, WebSocketSession channel, TerminalConfig config) {
|
||||
this.sessionId = sessionId;
|
||||
this.channel = channel;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user