|
|
|
@ -330,7 +330,7 @@ public class ZxjhBusinessServiceImpl implements ZxjhBusinessService {
|
|
|
|
|
ftpClient.connect(host, port);
|
|
|
|
|
ftpClient.login(username, password);
|
|
|
|
|
ftpClient.enterLocalPassiveMode();
|
|
|
|
|
|
|
|
|
|
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
|
|
|
|
File localFile = new File(localFilePath);
|
|
|
|
|
outputStream = new FileOutputStream(localFile);
|
|
|
|
|
|
|
|
|
@ -385,4 +385,64 @@ public class ZxjhBusinessServiceImpl implements ZxjhBusinessService {
|
|
|
|
|
throw new BaseException("获取文件页码出错");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void downFile(String sourcePath, String downPath) throws Exception{
|
|
|
|
|
File file = new File(downPath);
|
|
|
|
|
if(!file.exists()){
|
|
|
|
|
file.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
//文件地址形似ftp://AdminPLAT:Plat.2023@192.168.12.90:21/PaperlessData/2024/03/05/Emr/b1162dd9-c47a-4353-8572-37667f6114bc.pdf
|
|
|
|
|
//获取文件后最
|
|
|
|
|
String end = sourcePath.substring(sourcePath.lastIndexOf("."));
|
|
|
|
|
//本地文件名
|
|
|
|
|
String fileName = UUID.randomUUID()+end; // 假设要下载的文件名为example.pdf
|
|
|
|
|
//文件本地存储路径
|
|
|
|
|
String localFilePath = downPath +File.separator+ fileName;
|
|
|
|
|
|
|
|
|
|
URI uri = new URI(sourcePath);
|
|
|
|
|
String host = uri.getHost();
|
|
|
|
|
int port = uri.getPort() == -1 ? 21 : uri.getPort(); // 默认端口号为21
|
|
|
|
|
String userInfo = uri.getRawUserInfo();
|
|
|
|
|
String username = "";
|
|
|
|
|
String password = "";
|
|
|
|
|
if(userInfo != null) {
|
|
|
|
|
String[] userInfoArray = userInfo.split(":");
|
|
|
|
|
if(userInfoArray.length >= 1) {
|
|
|
|
|
username = URLDecoder.decode(userInfoArray[0], "UTF-8");
|
|
|
|
|
}
|
|
|
|
|
if(userInfoArray.length >= 2) {
|
|
|
|
|
password = URLDecoder.decode(userInfoArray[1], "UTF-8");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String path = uri.getPath();
|
|
|
|
|
FTPClient ftpClient = new FTPClient();
|
|
|
|
|
OutputStream outputStream=null;
|
|
|
|
|
try {
|
|
|
|
|
ftpClient.connect(host, port);
|
|
|
|
|
ftpClient.login(username, password);
|
|
|
|
|
ftpClient.enterLocalPassiveMode();
|
|
|
|
|
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
|
|
|
|
|
|
|
|
|
File localFile = new File(localFilePath);
|
|
|
|
|
outputStream = new FileOutputStream(localFile);
|
|
|
|
|
|
|
|
|
|
ftpClient.retrieveFile(path, outputStream);
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
log.error(ex.getMessage(),ex);
|
|
|
|
|
} finally {
|
|
|
|
|
if (ftpClient.isConnected()) {
|
|
|
|
|
try {
|
|
|
|
|
ftpClient.logout();
|
|
|
|
|
ftpClient.disconnect();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
log.error(ex.getMessage(),ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( outputStream!=null){
|
|
|
|
|
outputStream.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|