Kaynağa Gözat

add main commit
Commit 43243b00: 因應ftp server 只開放ftps 連線使用
調整FW 放到 ftp server 服務功能
替換設定檔 https & ftps

Robert 1 yıl önce
ebeveyn
işleme
fed06618bb

+ 5 - 1
TestTool.RemoteTriggerAPP/FTPClient.cs

@@ -129,6 +129,8 @@ namespace TestTool.RemoteTriggerAPP
             reqFTP.UseBinary = true;
             // 上传文件时通知服务器文件的大小 
             reqFTP.ContentLength = fileInf.Length;
+            reqFTP.EnableSsl = true;
+
             int buffLength = 2048000;// 缓冲大小设置为200kb 
             byte[] buff = new byte[buffLength];
             // 打开一个文件流 (System.IO.FileStream) 去读上传的文件 
@@ -191,7 +193,9 @@ namespace TestTool.RemoteTriggerAPP
             long filesize = 0;
             try
             {
+                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                 FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(remoteFilepath);
+                reqFTP.EnableSsl = true;
                 reqFTP.KeepAlive = false;
                 reqFTP.UseBinary = true;
                 reqFTP.Credentials = new NetworkCredential(UesrName, Password);//用户,密码
@@ -200,7 +204,7 @@ namespace TestTool.RemoteTriggerAPP
                 filesize = response.ContentLength;
                 return filesize;
             }
-            catch
+            catch (Exception ex)
             {
                 return 0;
             }

+ 162 - 0
TestTool.RemoteTriggerAPP/FluentFTPClient.cs

@@ -0,0 +1,162 @@
+using FluentFTP;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net.NetworkInformation;
+using System.Security.Authentication;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestTool.RemoteTriggerAPP
+{
+    internal class FluentFTPClient
+    {
+        #region 属性与构造函数
+
+        /// <summary>
+        /// IP地址
+        /// </summary>
+        public string IpAddr { get; set; }
+
+        /// <summary>
+        /// 相对路径
+        /// </summary>
+        public string RelatePath { get; set; }
+
+        /// <summary>
+        /// 端口号
+        /// </summary>
+        public int Port { get; set; }
+
+        /// <summary>
+        /// 用户名
+        /// </summary>
+        public string UserName { get; set; }
+
+        /// <summary>
+        /// 密码
+        /// </summary>
+        public string Password { get; set; }
+
+
+
+        public FluentFTPClient(string ipAddr, int port, string userName, string password, string relatePath)
+        {
+            this.IpAddr = ipAddr;
+            this.Port = port;
+            this.UserName = userName;
+            this.Password = password;
+            this.RelatePath = relatePath;
+        }
+
+        #endregion
+
+        #region 方法
+
+        public FtpListItem[] ListDir()
+        {
+            FtpListItem[] lists;
+            using (var client = new FtpClient(this.IpAddr, this.UserName, this.Password, this.Port))
+            {
+                client.Config.EncryptionMode = FtpEncryptionMode.Explicit;
+                client.Config.SslProtocols = SslProtocols.Tls12;
+                client.ValidateCertificate += Client_ValidateCertificate;
+                client.Connect();
+
+                client.SetWorkingDirectory(this.RelatePath);
+                lists = client.GetListing();
+            }
+            return lists;
+        }
+
+        private void Client_ValidateCertificate(FluentFTP.Client.BaseClient.BaseFtpClient control, FtpSslValidationEventArgs e)
+        {
+            if (e.PolicyErrors != System.Net.Security.SslPolicyErrors.None)
+            {
+                e.Accept = false;
+            }
+            else
+            {
+                e.Accept = true;
+            }
+        }
+
+        async internal Task<bool> UploadFileAsync(string localFilePath, string remoteFilePath)
+        {
+            bool isOk = false;
+            using (var client = new AsyncFtpClient(this.IpAddr, this.UserName, this.Password, this.Port))
+            {
+                client.Config.EncryptionMode = FtpEncryptionMode.Implicit;
+                client.Config.SslProtocols = SslProtocols.Tls12;
+                client.ValidateCertificate += Client_ValidateCertificate;
+                await client.SetWorkingDirectory(this.RelatePath);
+                await client.Connect();
+
+
+                var status = await client.UploadFile(localFilePath, "/" + remoteFilePath, FtpRemoteExists.Overwrite, false, FtpVerify.Retry);
+                isOk = status == FtpStatus.Success;
+
+            }
+
+            return isOk;
+
+
+        }
+
+
+
+        public bool Upload(string dir, string file)
+        {
+            bool isOk = false;
+            FileInfo fi = new FileInfo(Path.Combine(dir, file));
+            using (FileStream fs = fi.OpenRead())
+            {
+                //long length = fs.Length;
+                using (var client = new FtpClient(this.IpAddr, this.UserName, this.Password, this.Port))
+                {
+                    client.Config.EncryptionMode = FtpEncryptionMode.Implicit;
+                    client.Config.SslProtocols = SslProtocols.Tls12;
+                    client.ValidateCertificate += Client_ValidateCertificate;
+                    client.Connect();
+                    client.SetWorkingDirectory(this.RelatePath);
+                    string remotePath = Path.GetFileName(file);
+                    FtpStatus status = client.UploadStream(fs, remotePath, FtpRemoteExists.Overwrite, true);
+                    isOk = status == FtpStatus.Success;
+
+                }
+            }
+
+            return isOk;
+        }
+
+
+
+
+        /// <summary>
+        /// 下载ftp
+        /// </summary>
+        /// <param name="localAddress"></param>
+        /// <param name="remoteAddress"></param>
+        /// <returns></returns>
+        public bool DownloadFile(string localAddress, string remoteAddress)
+        {
+            using (var client = new FtpClient(this.IpAddr, this.UserName, this.Password, this.Port))
+            {
+                client.Config.EncryptionMode = FtpEncryptionMode.Explicit;
+                client.Config.SslProtocols = SslProtocols.Tls12;
+                client.ValidateCertificate += Client_ValidateCertificate;
+
+                client.SetWorkingDirectory("/");
+                client.Connect();
+                if (client.DownloadFile(localAddress, remoteAddress) == FtpStatus.Success)
+                {
+                    return true;
+                }
+                return false;
+            }
+        }
+
+        #endregion
+    }
+}

+ 361 - 48
TestTool.RemoteTriggerAPP/MainWindow.xaml

@@ -1,22 +1,63 @@
-<Window x:Class="TestTool.RemoteTriggerAPP.MainWindow"
-        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-        xmlns:local="clr-namespace:TestTool.RemoteTriggerAPP"      
-        mc:Ignorable="d"
-        Title="下發測試用工具(公司內網) V1.1.38 (20220622)" Height="481" Width="652">
+<Window
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:local="clr-namespace:TestTool.RemoteTriggerAPP"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    Title="下發測試用工具(公司內網) V1.1.39 (20230223)"
+    Width="652"
+    Height="481"
+    mc:Ignorable="d"
+    x:Class="TestTool.RemoteTriggerAPP.MainWindow">
     <Viewbox>
         <Grid Margin="0,2,2,0">
             <Grid.ColumnDefinitions>
-                <ColumnDefinition Width="109*"/>
-                <ColumnDefinition Width="222*"/>
+                <ColumnDefinition Width="109*" />
+                <ColumnDefinition Width="222*" />
             </Grid.ColumnDefinitions>
-            <Label Content="Charge Box Id:" HorizontalAlignment="Left" Height="27" Margin="69,23,0,0" VerticalAlignment="Top" Width="91"/>
-            <Label Content="Connector Id:" HorizontalAlignment="Left" Height="27" Margin="118,23,0,0" VerticalAlignment="Top" Width="92" Grid.Column="1"/>
-            <TextBox Name="uxChargeBoxIdTb" Text="OCTT_1" HorizontalAlignment="Left" Height="27" Margin="179,23,0,0" VerticalAlignment="Top" Width="148" Grid.ColumnSpan="2" LostFocus="uxChargeBoxIdTb_LostFocus"/>
-            <TextBox Name="uxConnectorIdTb" Text="1" HorizontalAlignment="Left" Height="27" Margin="210,23,0,0" VerticalAlignment="Top" Width="35" Grid.Column="1"/>
-            <ComboBox Name="uxCmdCb" HorizontalAlignment="Left" Margin="5.333,189,0,0" VerticalAlignment="Top" Width="253" Height="34" SelectionChanged="UxCmdCb_SelectionChanged" Grid.Column="1">
+            <Label
+                Width="91"
+                Height="27"
+                Margin="69,23,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="Charge Box Id:" />
+            <Label
+                Grid.Column="1"
+                Width="92"
+                Height="27"
+                Margin="118,23,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="Connector Id:" />
+            <TextBox
+                Name="uxChargeBoxIdTb"
+                Grid.ColumnSpan="2"
+                Width="148"
+                Height="27"
+                Margin="179,23,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text="OCTT_1"
+                LostFocus="uxChargeBoxIdTb_LostFocus" />
+            <TextBox
+                Name="uxConnectorIdTb"
+                Grid.Column="1"
+                Width="35"
+                Height="27"
+                Margin="210,23,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text="1" />
+            <ComboBox
+                Name="uxCmdCb"
+                Grid.Column="1"
+                Width="253"
+                Height="34"
+                Margin="5.333,189,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                SelectionChanged="UxCmdCb_SelectionChanged">
                 <ComboBoxItem>WrongAction(破壞模式專用)</ComboBoxItem>
                 <ComboBoxItem>ChangeAvailability_Inoperative</ComboBoxItem>
                 <ComboBoxItem>ChangeAvailability_Operative</ComboBoxItem>
@@ -48,42 +89,314 @@
                 <ComboBoxItem>TriggerMessage_MeterValues</ComboBoxItem>
                 <ComboBoxItem>TriggerMessage_StatusNotification</ComboBoxItem>
             </ComboBox>
-            <Label  Content="Remote Trigger Cmd:" HorizontalAlignment="Left" Height="27" Margin="69,191,0,0" VerticalAlignment="Top" Width="137"/>
-            <Button Name="uxSubmitBtn" Content="Submit" HorizontalAlignment="Left" Margin="265.333,188,0,0" VerticalAlignment="Top" Width="51" Height="34" Click="UxSubmitBtn_Click" Grid.Column="1"/>
-            <TextBox Name="uxMsgTb" HorizontalAlignment="Left" Height="80" Margin="84,346,0,0" VerticalAlignment="Top" Width="471" Grid.ColumnSpan="2"/>
-            <Label Content="Msg:" HorizontalAlignment="Left" Height="27" Margin="75,314,0,0" VerticalAlignment="Top" Width="43" RenderTransformOrigin="0.744,3.407"/>
-            <Label Content="Id Tag:" HorizontalAlignment="Left" Height="27" Margin="71,74,0,0" VerticalAlignment="Top" Width="47"/>
-            <TextBox x:Name="uxIdTagTb" Text="TestTool" HorizontalAlignment="Left" Height="27" Margin="121,74,0,0" VerticalAlignment="Top" Width="63" RenderTransformOrigin="3.714,1"/>
-            <Label Content="TransactionId:" HorizontalAlignment="Left" Height="27" Margin="152,74,0,0" VerticalAlignment="Top" Width="100" Grid.Column="1"/>
-            <TextBox x:Name="uxTransactionIdTb" Text="0" HorizontalAlignment="Left" Height="27" Margin="245,74,0,0" VerticalAlignment="Top" Width="44" RenderTransformOrigin="3.714,1" Grid.Column="1"/>
-            <Label Content="ParentId Tag:" HorizontalAlignment="Left" Height="27" Margin="191,74,0,0" VerticalAlignment="Top" Width="87" Grid.ColumnSpan="2"/>
-            <TextBox x:Name="uxParentIdTagTb" Text="TestTool" HorizontalAlignment="Left" Height="27" Margin="75,74,0,0" VerticalAlignment="Top" Width="73" RenderTransformOrigin="3.714,1" Grid.Column="1"/>
-            <Label Content="Configuration Key:" HorizontalAlignment="Left" Height="27" Margin="71,119,0,0" VerticalAlignment="Top" Width="120"/>
-            <TextBox x:Name="uxConfigKeyTb" Text="ConnectionTimeOut" HorizontalAlignment="Left" Height="27" Margin="196,119,0,0" VerticalAlignment="Top" Width="138" RenderTransformOrigin="3.714,1" Grid.ColumnSpan="2"/>
-            <Label Content=" Value:" HorizontalAlignment="Left" Height="27" Margin="124.333,119,0,0" VerticalAlignment="Top" Width="54" Grid.Column="1"/>
-            <TextBox x:Name="uxConfigValueTb" Text="30" HorizontalAlignment="Left" Height="27" Margin="180,117,0,0" VerticalAlignment="Top" Width="52" RenderTransformOrigin="3.714,1" Grid.Column="1"/>
+            <Label
+                Width="137"
+                Height="27"
+                Margin="69,191,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="Remote Trigger Cmd:" />
+            <Button
+                Name="uxSubmitBtn"
+                Grid.Column="1"
+                Width="51"
+                Height="34"
+                Margin="265.333,188,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Click="UxSubmitBtn_Click"
+                Content="Submit" />
+            <TextBox
+                Name="uxMsgTb"
+                Grid.ColumnSpan="2"
+                Width="471"
+                Height="80"
+                Margin="84,346,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top" />
+            <Label
+                Width="43"
+                Height="27"
+                Margin="75,314,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="Msg:"
+                RenderTransformOrigin="0.744,3.407" />
+            <Label
+                Width="47"
+                Height="27"
+                Margin="71,74,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="Id Tag:" />
+            <TextBox
+                x:Name="uxIdTagTb"
+                Width="63"
+                Height="27"
+                Margin="121,74,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text="TestTool"
+                RenderTransformOrigin="3.714,1" />
+            <Label
+                Grid.Column="1"
+                Width="100"
+                Height="27"
+                Margin="152,74,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="TransactionId:" />
+            <TextBox
+                x:Name="uxTransactionIdTb"
+                Grid.Column="1"
+                Width="44"
+                Height="27"
+                Margin="245,74,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text="0"
+                RenderTransformOrigin="3.714,1" />
+            <Label
+                Grid.ColumnSpan="2"
+                Width="87"
+                Height="27"
+                Margin="191,74,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="ParentId Tag:" />
+            <TextBox
+                x:Name="uxParentIdTagTb"
+                Grid.Column="1"
+                Width="73"
+                Height="27"
+                Margin="75,74,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text="TestTool"
+                RenderTransformOrigin="3.714,1" />
+            <Label
+                Width="120"
+                Height="27"
+                Margin="71,119,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="Configuration Key:" />
+            <TextBox
+                x:Name="uxConfigKeyTb"
+                Grid.ColumnSpan="2"
+                Width="138"
+                Height="27"
+                Margin="196,119,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text="ConnectionTimeOut"
+                RenderTransformOrigin="3.714,1" />
+            <Label
+                Grid.Column="1"
+                Width="54"
+                Height="27"
+                Margin="124.333,119,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content=" Value:" />
+            <TextBox
+                x:Name="uxConfigValueTb"
+                Grid.Column="1"
+                Width="52"
+                Height="27"
+                Margin="180,117,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text="30"
+                RenderTransformOrigin="3.714,1" />
 
-            <Label Visibility="Visible"   Content="Upload Firmware:" HorizontalAlignment="Left" Height="27" Margin="69,243,0,0" VerticalAlignment="Top" Width="113"/>
-            <TextBox Visibility="Visible" x:Name="uxUploadFileTb" Text="" HorizontalAlignment="Left" Height="27" Margin="182,244,0,0" VerticalAlignment="Top" Width="210" RenderTransformOrigin="3.714,1" Grid.ColumnSpan="2"/>
-            <Button Visibility="Visible"  x:Name="uxFileSubmitBtn" Content="..." HorizontalAlignment="Left" Margin="187.333,241,0,0" VerticalAlignment="Top" Width="46" Height="29" Click="uxFileSubmitBtn_Click" Grid.Column="1"/>
-            <Button Visibility="Visible"  x:Name="uxUploadBtn" Content="Upload" HorizontalAlignment="Left" Margin="259.333,238,0,0" VerticalAlignment="Top" Width="52" Height="34" Click="uxUploadBtn_Click" Grid.Column="1"/>
-            <Label Visibility="Visible"   Content="Publish Version:" HorizontalAlignment="Left" Height="27" Margin="69,292,0,0" VerticalAlignment="Top" Width="113"/>
-            <ComboBox Visibility="Visible"  x:Name="uxPublishCb" HorizontalAlignment="Left" Margin="179,292,0,0" VerticalAlignment="Top" Width="213" Height="34" SelectionChanged="uxPublishCb_SelectionChanged" Grid.ColumnSpan="2"/>
-            <Button Visibility="Visible"  x:Name="uxRefreshBtn" Content="Refresh" HorizontalAlignment="Left" Margin="192.333,292,0,0" VerticalAlignment="Top" Width="53" Height="34" Click="uxRefreshBtn_Click" Grid.Column="1"/>
-            <Button Visibility="Visible"  x:Name="uxPublishBtn" Content="Publish" HorizontalAlignment="Left" Margin="258.333,292,0,0" VerticalAlignment="Top" Width="53" Height="34" Click="uxPublishBtn_Click" Grid.Column="1"/>
-            <Label Visibility="Visible"  Content="ReservationId:" HorizontalAlignment="Left" Height="27" Margin="262,23,0,0" VerticalAlignment="Top" Width="100" Grid.Column="1"/>
-            <TextBox Visibility="Visible"  x:Name="uxReservationTb" Text="0" HorizontalAlignment="Left" Height="27" Margin="367,23,0,0" VerticalAlignment="Top" Width="44" RenderTransformOrigin="3.714,1" Grid.Column="1"/>
-            <Button  Visibility="Visible" x:Name="uxClearPublishBtn" Content="Clear Publish" HorizontalAlignment="Left" Margin="325.333,292,0,0" VerticalAlignment="Top" Width="86" Height="34" Click="uxClearPublishBtn_Click" Grid.Column="1"/>
-            <Button Visibility="Visible"  x:Name="uxFTPUploadBtn" Content="Upload(FTP)" HorizontalAlignment="Left" Margin="325.333,238,0,0" VerticalAlignment="Top" Width="86" Height="34" Click="uxFTPUploadBtn_Click" RenderTransformOrigin="2.058,0.529" Grid.Column="1"/>
+            <Label
+                Width="113"
+                Height="27"
+                Margin="69,243,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="Upload Firmware:"
+                Visibility="Visible" />
+            <TextBox
+                x:Name="uxUploadFileTb"
+                Grid.ColumnSpan="2"
+                Width="210"
+                Height="27"
+                Margin="182,244,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text=""
+                RenderTransformOrigin="3.714,1"
+                Visibility="Visible" />
+            <Button
+                x:Name="uxFileSubmitBtn"
+                Grid.Column="1"
+                Width="46"
+                Height="29"
+                Margin="187.333,241,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Click="uxFileSubmitBtn_Click"
+                Content="..."
+                Visibility="Visible" />
+            <Button
+                x:Name="uxUploadBtn"
+                Grid.Column="1"
+                Width="52"
+                Height="34"
+                Margin="259.333,238,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Click="uxUploadBtn_Click"
+                Content="Upload"
+                Visibility="Visible" />
+            <Label
+                Width="113"
+                Height="27"
+                Margin="69,292,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="Publish Version:"
+                Visibility="Visible" />
+            <ComboBox
+                x:Name="uxPublishCb"
+                Grid.ColumnSpan="2"
+                Width="213"
+                Height="34"
+                Margin="179,292,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                SelectionChanged="uxPublishCb_SelectionChanged"
+                Visibility="Visible" />
+            <Button
+                x:Name="uxRefreshBtn"
+                Grid.Column="1"
+                Width="53"
+                Height="34"
+                Margin="192.333,292,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Click="uxRefreshBtn_Click"
+                Content="Refresh"
+                Visibility="Visible" />
+            <Button
+                x:Name="uxPublishBtn"
+                Grid.Column="1"
+                Width="53"
+                Height="34"
+                Margin="258.333,292,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Click="uxPublishBtn_Click"
+                Content="Publish"
+                Visibility="Visible" />
+            <Label
+                Grid.Column="1"
+                Width="100"
+                Height="27"
+                Margin="262,23,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="ReservationId:"
+                Visibility="Visible" />
+            <TextBox
+                x:Name="uxReservationTb"
+                Grid.Column="1"
+                Width="44"
+                Height="27"
+                Margin="367,23,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text="0"
+                RenderTransformOrigin="3.714,1"
+                Visibility="Visible" />
+            <Button
+                x:Name="uxClearPublishBtn"
+                Grid.Column="1"
+                Width="86"
+                Height="34"
+                Margin="325.333,292,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Click="uxClearPublishBtn_Click"
+                Content="Clear Publish"
+                Visibility="Visible" />
+            <Button
+                x:Name="uxFTPUploadBtn"
+                Grid.Column="1"
+                Width="86"
+                Height="34"
+                Margin="325.333,238,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Click="uxFTPUploadBtn_Click"
+                Content="Upload(FTP)"
+                RenderTransformOrigin="2.058,0.529"
+                Visibility="Visible" />
 
-            <Label Content=" Expiry Time:" HorizontalAlignment="Left" Height="27" Margin="237,119,0,0" VerticalAlignment="Top" Width="80" Grid.Column="1"/>
+            <Label
+                Grid.Column="1"
+                Width="80"
+                Height="27"
+                Margin="237,119,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content=" Expiry Time:" />
 
-            <TextBox x:Name="uxExpiryTimeTb"  Margin="325,117,10,283" Text="2020/02/06 12:00" Grid.Column="1"></TextBox>
-            <Label Content="LocalListSize:" HorizontalAlignment="Left" Height="27" Margin="294,74,0,0" VerticalAlignment="Top" Width="87" Grid.Column="1"/>
-            <TextBox x:Name="uxLocalListSizeTb" Text="0" HorizontalAlignment="Left" Height="27" Margin="381,74,0,0" VerticalAlignment="Top" Width="44" RenderTransformOrigin="3.714,1" Grid.Column="1"/>
-            <CheckBox x:Name="uxDestroyCb" Content="破壞模式" HorizontalAlignment="Left" Height="27" Margin="325.333,191,0,0" VerticalAlignment="Top" Width="100" Grid.Column="1" FontSize="18" Foreground="#FFF11010" Checked="uxDestroyCb_Checked" Unchecked="uxDestroyCb_Unchecked"/>
-            <Label Content="WrongActionName:" HorizontalAlignment="Left" Height="27" Margin="71,151,0,0" VerticalAlignment="Top" Width="126"/>
-            <TextBox x:Name="uxWrongActionNameTb" Text="WrongAction" HorizontalAlignment="Left" Height="27" Margin="196,157,0,0" VerticalAlignment="Top" Width="138" RenderTransformOrigin="3.714,1" Grid.ColumnSpan="2"/>
+            <TextBox
+                x:Name="uxExpiryTimeTb"
+                Grid.Column="1"
+                Margin="325,117,10,283"
+                Text="2020/02/06 12:00" />
+            <Label
+                Grid.Column="1"
+                Width="87"
+                Height="27"
+                Margin="294,74,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="LocalListSize:" />
+            <TextBox
+                x:Name="uxLocalListSizeTb"
+                Grid.Column="1"
+                Width="44"
+                Height="27"
+                Margin="381,74,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text="0"
+                RenderTransformOrigin="3.714,1" />
+            <CheckBox
+                x:Name="uxDestroyCb"
+                Grid.Column="1"
+                Width="100"
+                Height="27"
+                Margin="325.333,191,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                FontSize="18"
+                Checked="uxDestroyCb_Checked"
+                Content="破壞模式"
+                Foreground="#FFF11010"
+                Unchecked="uxDestroyCb_Unchecked" />
+            <Label
+                Width="126"
+                Height="27"
+                Margin="71,151,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Content="WrongActionName:" />
+            <TextBox
+                x:Name="uxWrongActionNameTb"
+                Grid.ColumnSpan="2"
+                Width="138"
+                Height="27"
+                Margin="196,157,0,0"
+                HorizontalAlignment="Left"
+                VerticalAlignment="Top"
+                Text="WrongAction"
+                RenderTransformOrigin="3.714,1" />
         </Grid>
     </Viewbox>
 </Window>

+ 60 - 78
TestTool.RemoteTriggerAPP/MainWindow.xaml.cs

@@ -45,7 +45,6 @@ namespace TestTool.RemoteTriggerAPP
 
         string action = "";
         List<UploadFile> publishes = new List<UploadFile>();
-        FTPClient UploadClient = new FTPClient(@"ftp://test.evsocket.phihong.com.cn", "testocpp", "testocpp");
         string chargingProfilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SetChargingProfile.json");
         string dataTransferPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataTransfer.json");
         int selectedPublish = -1;
@@ -54,22 +53,8 @@ namespace TestTool.RemoteTriggerAPP
 
         public MainWindow(IConfiguration configuration)
         {
-            var oo = new { idToken = "3345678", price = "Connection Fee: $2.11 NTD/time; Current Rate: $2.22 NTD/kWh;Occupancy Fee: $2.33 NTD/hr; Account Balance: $2444 NTD" };
-
-
-            var tt = new DataTransferRequest()
-            {
-                vendorId = "Phihong Technology",
-                messageId = "SetUserPrice",
-                data = JsonConvert.SerializeObject(oo)
-            };
-
-            var ttt = JsonConvert.SerializeObject(tt);
-
-
             InitializeComponent();
             Loaded += MainWindow_Loaded;
-            UploadClient.OnUploadProgress += UploadClient_OnUploadProgress;
             this.configuration = configuration;
         }
 
@@ -600,9 +585,9 @@ namespace TestTool.RemoteTriggerAPP
                 //        status = AuthorizationStatus.ConcurrentTx
                 //    }
                 //});
-             
 
-                for (int i = 0; i < size ; i++)
+
+                for (int i = 0; i < size; i++)
                 {
                     request.localAuthorizationList.Add(new AuthorizationData()
                     {
@@ -942,84 +927,81 @@ namespace TestTool.RemoteTriggerAPP
                 uxMsgTb.Text = "Please select upload file!";
                 return;
             }
+            string filePath = uxUploadFileTb.Text;
 
-            FileInfo f = new FileInfo(uxUploadFileTb.Text);
-
-            int size = (int)f.Length;
-            string md5 = "";
-            string filePreUrl = configuration["UpdateFWPreUrl"];
-            using (WebClient client = new WebClient())
-            {
-                client.UseDefaultCredentials = false;
-                client.Headers.Add("Content-Type", "application/octet-stream");
-                using (Stream fileStream = File.OpenRead(uxUploadFileTb.Text))
-                {
-                    var _md5 = MD5.Create();
-                    var hash = _md5.ComputeHash(fileStream);
-                    md5 = BitConverter.ToString(hash).Replace("-", String.Empty).ToLowerInvariant();
-
-                }
-            }
-
-            UploadFile ufObj = new UploadFile();
-            ufObj.CreatedOn = DateTime.UtcNow.ToUniversalTime();
-            ufObj.FileExtensionName = System.IO.Path.GetExtension(uxUploadFileTb.Text);
-            ufObj.Id = Guid.NewGuid().ToString();
-            ufObj.FileName = md5 + ufObj.FileExtensionName;
-            ufObj.FilePath = "~/UploadFiles/Fw/" + ufObj.FileName;
-            ufObj.FileSize = size;
-            ufObj.FileMD5 = md5;
-            ufObj.OriginName = System.IO.Path.GetFileName(uxUploadFileTb.Text);
-            ufObj.FileUrl = new Uri(Properties.Settings.Default.UpdateFWPreUrl + ufObj.FilePath.Replace("~/", "")).ToString();
-            ufObj.VendorId = "TestTool";
-            ufObj.ModelName = "TestTool";
-            ufObj.ModuleId = 0;
-
-            using (var db = new MainDBContext())
-            {
-                db.UploadFile.Add(ufObj);
-                db.SaveChanges();
-
-            }
 
-            string filePath = uxUploadFileTb.Text;
-            uxMsgTb.Text = "Uploading........";
 
             Task.Run(async () =>
             {
-                await UploadTask(filePath, ufObj.FileName);
-            });
-
-
-
-
-
-
-
-
-
 
+                await UploadTask(filePath, false);
+            });
         }
 
-        private async Task UploadTask(string filePath, string fileName)
+        private async Task UploadTask(string filepath, bool isFTP)
         {
+            try
+            {
+                await Dispatcher.BeginInvoke(new Action(() =>
+                {
+                    uxMsgTb.Text = "Uploading........";
 
-            bool uploadResult = UploadClient.FtpUploadBroken(filePath, @"ftp://ocpp.phihong.com.tw/" + fileName);
+                }));
 
-            await Dispatcher.BeginInvoke(new Action(() =>
-            {
-                if (uploadResult)
+                FileInfo f = new FileInfo(filepath);
+                int size = (int)f.Length;
+                string fileMD5 = "";  //get file md5
+                using (var md5 = MD5.Create())
                 {
-                    uxMsgTb.Text = "Current Progress :100 %";
-                    Thread.CurrentThread.Join(100);
+                    using (var stream = File.OpenRead(filepath))
+                    {
+                        fileMD5 = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", String.Empty).ToLower();
+                    }
                 }
-                uxMsgTb.Text = "Upload File Result :" + (uploadResult ? "Success" : "Fail");
+                string filePreUrl = isFTP ? Properties.Settings.Default.FTPUpdateFWPreUrl : Properties.Settings.Default.UpdateFWPreUrl;
+
+                UploadFile ufObj = new UploadFile();
+                ufObj.CreatedOn = DateTime.Now.ToUniversalTime();
+                ufObj.FileExtensionName = System.IO.Path.GetExtension(filepath);
+                ufObj.Id = Guid.NewGuid().ToString();
+                ufObj.FileName = fileMD5 + System.IO.Path.GetExtension(filepath);
+                ufObj.FilePath = isFTP ? "~/" + ufObj.FileName : "~/UploadFiles/FW/" + ufObj.FileName;
+                ufObj.FileSize = size;
+                ufObj.FileMD5 = fileMD5;
+                ufObj.OriginName = System.IO.Path.GetFileName(filepath);
+                ufObj.FileUrl = new Uri(filePreUrl + ufObj.FilePath.Replace("~/", "")).ToString();
+                ufObj.VendorId = "TestTool";
+                ufObj.ModelName = "TestTool";
+                ufObj.ModuleId = 0;
+
+                using (var db = new MainDBContext())
+                {
+                    db.UploadFile.Add(ufObj);
+                    await db.SaveChangesAsync();
 
+                }
 
-            }));
+                FluentFTPClient ftpClient = new FluentFTPClient("ocpp.phihong.com.tw", 5002, "testocpp", "testocpp", "/");
+                //Properties.Settings.Default.UpdateFWPreUrl
+                bool uploadResult = await ftpClient.UploadFileAsync(filepath, ufObj.FileName);
 
+                await Dispatcher.BeginInvoke(new Action(() =>
+                {
+                    if (uploadResult)
+                    {
+                        uxMsgTb.Text = "Current Progress :100 %";
+                        Thread.CurrentThread.Join(100);
+                    }
+                    uxMsgTb.Text = "Upload File Result :" + (uploadResult ? "Success" : "Fail");
 
 
+                }));
+
+            }
+            catch (Exception ex)
+            {
+
+            }
 
         }
 
@@ -1086,7 +1068,7 @@ namespace TestTool.RemoteTriggerAPP
 
             Task.Run(async () =>
             {
-                await UploadTask(filePath, ufObj.FileName);
+                await UploadTask(filePath, true);
             });
 
 

+ 1 - 0
TestTool.RemoteTriggerAPP/TestTool.RemoteTriggerAPP.csproj

@@ -46,6 +46,7 @@
     </BootstrapperPackage>
   </ItemGroup>
   <ItemGroup>
+    <PackageReference Include="FluentFTP" Version="46.0.2" />
     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.1" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.1" />
     <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />