|
@@ -7,6 +7,10 @@ import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.io.OutputStream;
|
|
|
+
|
|
|
+import org.apache.commons.net.ftp.FTPClient;
|
|
|
+import org.apache.commons.net.ftp.FTPReply;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
@@ -188,6 +192,45 @@ public class DataService {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ //ftp://FTPUser:ftpuser@188.188.2.1:6161/20240726/1AFB48FCF39241AA8DE61F85EE6D847F/Report/Report.jpg"
|
|
|
+ public String downloadFtpFile(String remoteFileName, String fileName) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ ftpClient.setControlEncoding("UTF-8");
|
|
|
+ ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
|
|
|
+ ftpClient.enterLocalPassiveMode();
|
|
|
+
|
|
|
+ File localFile = new File("/home/zskk/FTP_FILE" + File.separatorChar + fileName);
|
|
|
+ OutputStream os = new FileOutputStream(localFile);
|
|
|
+ //ftp中文名需要iso-8859-1字符
|
|
|
+ boolean flag2 = ftpClient.retrieveFile(new String(remoteFileName.getBytes("GBK"), "iso-8859-1"), os);
|
|
|
+ if (!flag2) {
|
|
|
+ System.out.println("没有找到" + remoteFileName + "---该文件");
|
|
|
+ localFile.delete();
|
|
|
+ } else {
|
|
|
+ System.out.println("=================== save success");
|
|
|
+ }
|
|
|
+ os.close();
|
|
|
+ ftpClient.logout();
|
|
|
+ ftpClient.disconnect();
|
|
|
+ return "/home/zskk/FTP_FILE" + File.separatorChar + fileName;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
Map <String,String> map = new HashMap<String,String>();
|