|
@@ -15,6 +15,12 @@ import org.apache.commons.net.ftp.FTPClient;
|
|
|
import org.apache.commons.net.ftp.FTPReply;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.amazonaws.auth.AWSCredentialsProvider;
|
|
|
+import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
|
|
+import com.amazonaws.auth.BasicAWSCredentials;
|
|
|
+import com.amazonaws.client.builder.AwsClientBuilder;
|
|
|
+import com.amazonaws.services.s3.AmazonS3;
|
|
|
+import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
|
|
import com.jfinal.core.Controller;
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
@@ -70,45 +76,57 @@ public class ViewController extends Controller {
|
|
|
// TODO Auto-generated method stub
|
|
|
try {
|
|
|
|
|
|
- FTPClient ftpClient = new FTPClient();
|
|
|
- int reply;
|
|
|
-
|
|
|
- try {
|
|
|
- ftpClient.connect(PropKit.get("ftp_host"), PropKit.getInt("ftp_port"));
|
|
|
- ftpClient.login(PropKit.get("ftp_user"), PropKit.get("ftp_password"));
|
|
|
- reply = ftpClient.getReplyCode();
|
|
|
- if (!FTPReply.isPositiveCompletion(reply)) {
|
|
|
- ftpClient.disconnect();
|
|
|
-// return null;
|
|
|
- this.renderText("noconn");
|
|
|
-
|
|
|
- }
|
|
|
- ftpClient.setControlEncoding("UTF-8");
|
|
|
- ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
|
|
- ftpClient.enterLocalPassiveMode();
|
|
|
-
|
|
|
- File localFile = new File("/home/zskk/FTP_FILE" + File.separatorChar + "123.jpg");
|
|
|
- OutputStream os = new FileOutputStream(localFile);
|
|
|
- //ftp中文名需要iso-8859-1字符
|
|
|
- boolean flag2 = ftpClient.retrieveFile(new String("20240726/1AFB48FCF39241AA8DE61F85EE6D847F/Report/Report.jpg".getBytes("GBK"), "iso-8859-1"), os);
|
|
|
- if (!flag2) {
|
|
|
- System.out.println("没有找到" + "20240726/1AFB48FCF39241AA8DE61F85EE6D847F/Report/Report.jpg" + "---该文件");
|
|
|
- localFile.delete();
|
|
|
- } else {
|
|
|
- System.out.println("=================== save success");
|
|
|
- }
|
|
|
- os.close();
|
|
|
- ftpClient.logout();
|
|
|
- ftpClient.disconnect();
|
|
|
-// return "/home/zskk/FTP_FILE" + File.separatorChar + fileName;
|
|
|
- this.renderText("succ");
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- this.renderText(e.toString());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+// FTPClient ftpClient = new FTPClient();
|
|
|
+// int reply;
|
|
|
+//
|
|
|
+// try {
|
|
|
+// ftpClient.connect(PropKit.get("ftp_host"), PropKit.getInt("ftp_port"));
|
|
|
+// ftpClient.login(PropKit.get("ftp_user"), PropKit.get("ftp_password"));
|
|
|
+// reply = ftpClient.getReplyCode();
|
|
|
+// if (!FTPReply.isPositiveCompletion(reply)) {
|
|
|
+// ftpClient.disconnect();
|
|
|
+//// return null;
|
|
|
+// this.renderText("noconn");
|
|
|
+//
|
|
|
+// }
|
|
|
+// ftpClient.setControlEncoding("UTF-8");
|
|
|
+// ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
|
|
+// ftpClient.enterLocalPassiveMode();
|
|
|
+//
|
|
|
+// File localFile = new File("/home/zskk/FTP_FILE" + File.separatorChar + "123.jpg");
|
|
|
+// OutputStream os = new FileOutputStream(localFile);
|
|
|
+// //ftp中文名需要iso-8859-1字符
|
|
|
+// boolean flag2 = ftpClient.retrieveFile(new String("20240726/1AFB48FCF39241AA8DE61F85EE6D847F/Report/Report.jpg".getBytes("GBK"), "iso-8859-1"), os);
|
|
|
+// if (!flag2) {
|
|
|
+// System.out.println("没有找到" + "20240726/1AFB48FCF39241AA8DE61F85EE6D847F/Report/Report.jpg" + "---该文件");
|
|
|
+// localFile.delete();
|
|
|
+// } else {
|
|
|
+// System.out.println("=================== save success");
|
|
|
+// }
|
|
|
+// os.close();
|
|
|
+// ftpClient.logout();
|
|
|
+// ftpClient.disconnect();
|
|
|
+//// return "/home/zskk/FTP_FILE" + File.separatorChar + fileName;
|
|
|
+// this.renderText("succ");
|
|
|
+//
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// this.renderText(e.toString());
|
|
|
+//
|
|
|
+// }
|
|
|
+ AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(PropKit.get("oss_endpoint"), PropKit.get("region"));
|
|
|
+ BasicAWSCredentials credentials = new BasicAWSCredentials(PropKit.get("oss_accessKey"), PropKit.get("oss_secretKey"));
|
|
|
+ AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
|
|
|
+ AmazonS3 client = AmazonS3ClientBuilder.standard()
|
|
|
+ .withEndpointConfiguration(endpointConfiguration)
|
|
|
+ .withCredentials(credentialsProvider).build();
|
|
|
+
|
|
|
+ String fileNameStr[] = "ftp://FTPUser:ftpuser@188.188.2.1:6161/20240726/1AFB48FCF39241AA8DE61F85EE6D847F/Report/Report.jpg".split("/");
|
|
|
+ String fileName = fileNameStr[fileNameStr.length - 3]+".jpg";
|
|
|
+ String fpString = fileNameStr[fileNameStr.length - 4]+"/"+fileNameStr[fileNameStr.length - 3]+"/"+fileNameStr[fileNameStr.length - 2]+"/"+fileNameStr[fileNameStr.length - 1];
|
|
|
+// String fileStorePath = getFileWithUrl(fpString, fileName);
|
|
|
+// String fileStorePath = downloadFtpFile(fpString, fileName);
|
|
|
+ this.renderText(fpString+"*******"+fileName);
|
|
|
|
|
|
// DataService dService = ServiceFactory.getService(DataService.class);
|
|
|
// Map<String, String> annex_params = new HashMap<>();
|