feat:日志管理登录以及查询文件夹内容修改
This commit is contained in:
parent
7b1c9d1784
commit
9c7be4c981
|
@ -14,6 +14,7 @@ import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -42,6 +43,8 @@ public class FTPUtil {
|
||||||
//声明FTP客户端
|
//声明FTP客户端
|
||||||
FTPClient ftp = new FTPClient();
|
FTPClient ftp = new FTPClient();
|
||||||
try {
|
try {
|
||||||
|
// 切换为本地被动模式,可以解决FTP上传后文件为空的问题,但需要服务器将FTP服务添加至防火墙白名单
|
||||||
|
ftp.enterLocalPassiveMode();
|
||||||
//连接
|
//连接
|
||||||
ftp.connect(host, port);
|
ftp.connect(host, port);
|
||||||
//登录
|
//登录
|
||||||
|
@ -101,9 +104,12 @@ public class FTPUtil {
|
||||||
|
|
||||||
public InputStream downloadFTPFile(String localPath, String fileName){
|
public InputStream downloadFTPFile(String localPath, String fileName){
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
FTPClient ftpClient = this.LoginFTP();
|
|
||||||
//传输模式
|
//传输模式
|
||||||
try {
|
try {
|
||||||
|
FTPClient ftpClient = this.LoginFTP();
|
||||||
|
if (Objects.isNull(ftpClient)){
|
||||||
|
throw new RuntimeException("ftp连接失败!");
|
||||||
|
}
|
||||||
List<String> paths = Arrays.asList(localPath.split("/"));
|
List<String> paths = Arrays.asList(localPath.split("/"));
|
||||||
if (CollectionUtils.isNotEmpty(paths)){
|
if (CollectionUtils.isNotEmpty(paths)){
|
||||||
for (String workPath:paths) {
|
for (String workPath:paths) {
|
||||||
|
@ -114,8 +120,6 @@ public class FTPUtil {
|
||||||
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
||||||
// 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
// 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项
|
||||||
ftpClient.setControlEncoding(encoding);
|
ftpClient.setControlEncoding(encoding);
|
||||||
// 切换为本地被动模式,可以解决FTP上传后文件为空的问题,但需要服务器将FTP服务添加至防火墙白名单
|
|
||||||
// ftp.enterLocalPassiveMode();
|
|
||||||
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
|
||||||
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
|
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
|
||||||
if (CollectionUtils.isNotEmpty(ftpFiles)){
|
if (CollectionUtils.isNotEmpty(ftpFiles)){
|
||||||
|
|
|
@ -35,11 +35,11 @@ public class LogManageController {
|
||||||
List<LogManage> result = new ArrayList<>();
|
List<LogManage> result = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
FTPClient ftpClient = ftpUtil.LoginFTP();
|
FTPClient ftpClient = ftpUtil.LoginFTP();
|
||||||
//切换工作文件路径
|
|
||||||
ftpClient.changeWorkingDirectory(workPath);
|
|
||||||
if(Objects.isNull(ftpClient)){
|
if(Objects.isNull(ftpClient)){
|
||||||
throw new RuntimeException("ftp连接失败!");
|
throw new RuntimeException("ftp连接失败!");
|
||||||
}
|
}
|
||||||
|
//切换工作文件路径
|
||||||
|
ftpClient.changeWorkingDirectory(workPath);
|
||||||
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listDirectories());
|
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listDirectories());
|
||||||
if (CollectionUtils.isNotEmpty(ftpFiles)){
|
if (CollectionUtils.isNotEmpty(ftpFiles)){
|
||||||
int num =1;
|
int num =1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user