fix: 修复下载远程Excel文件失败

This commit is contained in:
taojinlong
2025-03-09 20:32:42 +08:00
committed by taojinlong
parent 6f46355e97
commit 9b9329e081
2 changed files with 8 additions and 0 deletions

View File

@@ -767,6 +767,7 @@ public class ExcelUtils {
fileNames.put("tranName", tranName);
FTPClient ftpClient = new FTPClient();
try {
ftpClient.setConnectTimeout(5 * 1000);
ftpClient.connect(serverAddress, port);
ftpClient.login(username, password);
ftpClient.enterLocalPassiveMode();

View File

@@ -376,6 +376,13 @@ public class HttpClientUtil {
// 设置请求头
config.getHeader().forEach(httpGet::addHeader);
HttpResponse response = httpClient.execute(httpGet);
if (response.getStatusLine().getStatusCode() >= 400) {
String msg = EntityUtils.toString(response.getEntity(), config.getCharset());
if (StringUtils.isEmpty(msg)) {
msg = "StatusCode: " + response.getStatusLine().getStatusCode();
}
throw new Exception(msg);
}
String fileName = extractFileName(response, url);
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
String tranName = UUID.randomUUID().toString() + "." + suffix;