From 2f11a821259c77d8e48bb0b83e7f01b0f529b10a Mon Sep 17 00:00:00 2001
From: wbc <2597324127@qq.com>
Date: 星期三, 23 四月 2025 11:16:02 +0800
Subject: [PATCH] 3月27号首检巡检增加ftp获取文件列表

---
 MES.Service/service/QC/SJService.cs |   81 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/MES.Service/service/QC/SJService.cs b/MES.Service/service/QC/SJService.cs
index 47459cd..f853ea4 100644
--- a/MES.Service/service/QC/SJService.cs
+++ b/MES.Service/service/QC/SJService.cs
@@ -4,6 +4,7 @@
 using MES.Service.Modes;
 using MES.Service.util;
 using SqlSugar;
+using System.Net;
 using System.Xml.Linq;
 
 namespace MES.Service.service.QC;
@@ -69,7 +70,7 @@
             .OrderBy(a => a.BillNo, OrderByType.Desc)
             .ToPageList(queryObj.PageIndex, queryObj.Limit);
 
-        if(queryObj.Id != null)
+        /*if(queryObj.Id != null)
         {
 
 
@@ -88,7 +89,7 @@
                       return commit;
                   });
 
-        }
+        }*/
 
         
 
@@ -581,4 +582,80 @@
 
         return withOracle;
     }
+
+
+
+    public List<string> GetFtpFileList(string ftpAddress, string username, string password, string remotePath)
+    {
+        List<string> fileList = new List<string>();
+        try
+        {
+            // 鏋勯�燜TP璇锋眰鐨刄RI
+            string requestUri = $"{ftpAddress}/{remotePath}".TrimEnd('/'); // 纭繚璺緞鏍煎紡姝g‘
+
+            // 鍒涘缓FtpWebRequest瀵硅薄
+            FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(requestUri);
+            ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
+            ftpRequest.Credentials = new NetworkCredential(username, password);
+            ftpRequest.UseBinary = true;
+
+            // 鑾峰彇鍝嶅簲
+            using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse())
+            {
+                using (StreamReader responseReader = new StreamReader(ftpResponse.GetResponseStream()))
+                {
+                    string line = responseReader.ReadLine();
+                    while (line != null)
+                    {
+                        fileList.Add(line);
+                        line = responseReader.ReadLine();
+                    }
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+            Console.WriteLine("鑾峰彇FTP鏂囦欢鍒楄〃鏃跺彂鐢熼敊璇�: " + ex.Message);
+            
+        }
+        return fileList;
+    }
+
+
+    public byte[] DownloadFtpFile(string ftpAddress, string username, string password, string remotePath)
+    {
+        byte[] fileData = null;
+        try
+        {
+            // 鏋勯�燜TP璇锋眰鐨刄RI
+            string requestUri = $"{ftpAddress}/{remotePath}".TrimEnd('/'); // 纭繚璺緞鏍煎紡姝g‘
+
+            // 鍒涘缓FtpWebRequest瀵硅薄
+            FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(requestUri);
+            ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
+            ftpRequest.Credentials = new NetworkCredential(username, password);
+            ftpRequest.UseBinary = true;
+
+            // 鑾峰彇鍝嶅簲
+            using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse())
+            {
+                using (Stream responseStream = ftpResponse.GetResponseStream())
+                using (MemoryStream memoryStream = new MemoryStream())
+                {
+                    responseStream.CopyTo(memoryStream);
+                    fileData = memoryStream.ToArray();
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+            Console.WriteLine("涓嬭浇FTP鏂囦欢鏃跺彂鐢熼敊璇�: " + ex.Message);
+        }
+        return fileData;
+    }
+
+
+
+
+
 }
\ No newline at end of file

--
Gitblit v1.9.3