diff --git a/src/main/java/com/bellmann/common/enums/FileUrlEnum.java b/src/main/java/com/bellmann/common/enums/FileUrlEnum.java index 9f81e9f..104166a 100644 --- a/src/main/java/com/bellmann/common/enums/FileUrlEnum.java +++ b/src/main/java/com/bellmann/common/enums/FileUrlEnum.java @@ -4,13 +4,13 @@ import com.bellmann.common.base.IBaseEnum; import lombok.Getter; public enum FileUrlEnum implements IBaseEnum { - SOFT_VER_FILE_URL("0","devtypever/firmware/%s/"), - CORP_CONF_FILE_URL("1","devtypever/conf/%s/"), + SOFT_VER_FILE_URL("0","/devtypever/firmware/%s/"), + CORP_CONF_FILE_URL("1","/devtypever/conf/%s/"), - TR069_FILE_URL("3","tr069/%s"), - SERVICE_PLUGIN_FILE_URL("4","service/plugin/%s/"), - CPE_CONF_FILE_URL("5","device/conf/%s"), - OPERATE_TYPE_FILE_URL("7","opertype/plugin/%s"), + TR069_FILE_URL("3","/tr069/%s"), + SERVICE_PLUGIN_FILE_URL("4","/service/plugin/%s/"), + CPE_CONF_FILE_URL("5","/device/conf/%s"), + OPERATE_TYPE_FILE_URL("7","/opertype/plugin/%s"), ; @Getter private String value; diff --git a/src/main/java/com/bellmann/common/util/FTPUtils.java b/src/main/java/com/bellmann/common/util/FTPUtils.java index 0311320..d042ac0 100644 --- a/src/main/java/com/bellmann/common/util/FTPUtils.java +++ b/src/main/java/com/bellmann/common/util/FTPUtils.java @@ -17,7 +17,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.util.Arrays; /** * FTP工具类 @@ -184,7 +183,6 @@ public class FTPUtils { String path = changeEncoding(dirPath); changeAndMakeWorkingDir(path); String[] fileNames = ftpClient.listNames(); - log.info(Arrays.toString(fileNames)); if (fileNames == null || fileNames.length == 0) { throw new BusinessException(ResultCode.FILE_NOT_EXIST); } @@ -211,10 +209,8 @@ public class FTPUtils { if (ftpClient != null) { try { String path = changeEncoding(dirPath); - log.info("path:{}",path); changeAndMakeWorkingDir(path); String[] fileNames = ftpClient.listNames(); - log.info("fileName:{}",Arrays.toString(fileNames)); if (fileNames == null || fileNames.length == 0) { throw new BusinessException(ResultCode.FILE_NOT_EXIST); } diff --git a/src/main/java/com/bellmann/service/impl/FileOptionServiceImpl.java b/src/main/java/com/bellmann/service/impl/FileOptionServiceImpl.java index ef70a7d..86ce8e1 100644 --- a/src/main/java/com/bellmann/service/impl/FileOptionServiceImpl.java +++ b/src/main/java/com/bellmann/service/impl/FileOptionServiceImpl.java @@ -66,8 +66,8 @@ public class FileOptionServiceImpl implements FileOptionService { throw new BusinessException(ResultCode.FILE_NOT_EXIST); } String fileName = fileRecord.getFileName(); - String dirPath = fileRecord.getFileUrl(); - FTPUtils.download(fileServer,fileName,dirPath,response); + String fullPath = fileServer.getFtpRootDir()+fileRecord.getFileUrl(); + FTPUtils.download(fileServer,fileName,fullPath,response); } @Override @@ -82,8 +82,8 @@ public class FileOptionServiceImpl implements FileOptionService { throw new BusinessException(ResultCode.FILE_NOT_EXIST); } String fileName = fileRecord.getFileName(); - String dirPath = fileRecord.getFileUrl(); - return FTPUtils.download(fileServer,fileName,dirPath); + String fullPath = fileServer.getFtpRootDir()+fileRecord.getFileUrl(); + return FTPUtils.download(fileServer,fileName,fullPath); } @Override @@ -103,7 +103,8 @@ public class FileOptionServiceImpl implements FileOptionService { if (fileServer == null) { throw new BusinessException(ResultCode.FILE_SERVER_IS_NULL); } - return FTPUtils.removeFile(fileServer,fileUrl,fileName); + String fullPath = fileServer.getFtpRootDir()+fileUrl; + return FTPUtils.removeFile(fileServer,fullPath,fileName); } @@ -124,10 +125,11 @@ public class FileOptionServiceImpl implements FileOptionService { String newFileName = String.format("%s.%s",fileName,extension); //文件存放地址 //文件在FTP服务器所在文件夹目录 - String dirPath = fileServer.getFtpRootDir() + String.format(IBaseEnum.getLabelByValue(fileType,FileUrlEnum.class),fileType)+System.currentTimeMillis()/1000; + String dirPath = String.format(IBaseEnum.getLabelByValue(fileType,FileUrlEnum.class),fileType)+System.currentTimeMillis()/1000; + String fullPath = fileServer.getFtpRootDir() +dirPath; log.info("dirPath:{}",dirPath); try(InputStream in = file.getInputStream()) { - boolean upload = FTPUtils.upload(fileServer, newFileName, dirPath, in); + boolean upload = FTPUtils.upload(fileServer, newFileName, fullPath, in); if (!upload){ throw new BusinessException(ResultCode.USER_UPLOAD_FILE_ERROR); }