wbc
2025-04-23 2f11a821259c77d8e48bb0b83e7f01b0f529b10a
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
        {
            // 构造FTP请求的URI
            string requestUri = $"{ftpAddress}/{remotePath}".TrimEnd('/'); // 确保路径格式正确
            // 创建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
        {
            // 构造FTP请求的URI
            string requestUri = $"{ftpAddress}/{remotePath}".TrimEnd('/'); // 确保路径格式正确
            // 创建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;
    }
}