diff --git a/core/core-backend/src/main/java/io/dataease/datasource/provider/ExcelUtils.java b/core/core-backend/src/main/java/io/dataease/datasource/provider/ExcelUtils.java index 6f1a43facf..6015cd38ec 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/provider/ExcelUtils.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/provider/ExcelUtils.java @@ -30,6 +30,8 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; import java.io.*; +import java.net.URL; +import java.net.URLConnection; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.regex.Matcher; @@ -761,6 +763,12 @@ public class ExcelUtils { DEException.throwException(Translator.get("i18n_invalid_address")); } } + if(StringUtils.isNotEmpty(remoteExcelRequest.getUserName())){ + username = remoteExcelRequest.getUserName(); + } + if(StringUtils.isNotEmpty(remoteExcelRequest.getPasswd())){ + password = remoteExcelRequest.getPasswd(); + } filePath = filePath.startsWith("/") ? filePath.substring(1) : filePath; String suffix = filePath.substring(filePath.lastIndexOf(".") + 1); if (!Arrays.asList("csv", "xlsx", "xls").contains(suffix)) { @@ -772,20 +780,26 @@ public class ExcelUtils { fileNames.put("tranName", tranName); try { - String command = "curl -o " + localFilePath; // 在Unix/Linux系统中 - if (StringUtils.isNotEmpty(remoteExcelRequest.getUserName()) && StringUtils.isNotEmpty(remoteExcelRequest.getPasswd())) { - command = command + " -u " + remoteExcelRequest.getUserName() + ":" + remoteExcelRequest.getPasswd(); + URL url; + if(StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)){ + url= new URL("ftp://" + username + ":" +password + "@" + serverAddress + "/" + filePath); + }else { + url= new URL("ftp://" + serverAddress + "/" + filePath); } - command = command + " " + remoteExcelRequest.getUrl(); - Process process = Runtime.getRuntime().exec(command); - int exitValue = process.waitFor(); - if (exitValue != 0) { - DEException.throwException(Translator.get("i18n_file_download_failed")); + + URLConnection conn = url.openConnection(); + InputStream inputStream = conn.getInputStream(); + FileOutputStream outputStream = new FileOutputStream(localFilePath); + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); } + inputStream.close(); + outputStream.close(); + } catch (IOException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - throw new RuntimeException(e); + DEException.throwException(Translator.get("i18n_file_download_failed")); } return fileNames; } diff --git a/core/core-frontend/src/views/visualized/data/datasource/form/index.vue b/core/core-frontend/src/views/visualized/data/datasource/form/index.vue index 73ac6017ce..1b38056be1 100644 --- a/core/core-frontend/src/views/visualized/data/datasource/form/index.vue +++ b/core/core-frontend/src/views/visualized/data/datasource/form/index.vue @@ -402,7 +402,16 @@ const doValidateDs = request => { excelRequest.userName = Base64.encode(request.userName) excelRequest.passwd = Base64.encode(request.passwd) return loadRemoteFile(excelRequest) - .then(() => { + .then(res => { + dsLoading.value = false + if (!res) { + ElMessage.warning(res.msg) + return + } + if (res?.code !== 0) { + ElMessage.warning(res.msg) + return + } ElMessage.success(t('datasource.validate_success')) dsLoading.value = false }) diff --git a/de-xpack b/de-xpack index b3b53b559b..8e6ae99984 160000 --- a/de-xpack +++ b/de-xpack @@ -1 +1 @@ -Subproject commit b3b53b559b831f72466ced323e61df449d180ea7 +Subproject commit 8e6ae999842d1f68a4649a6e884d9b38f91def3a