Răsfoiți Sursa

该版本存在连接阿里云等服务器不稳定情况。

dail 3 ani în urmă
părinte
comite
5ec5bf49d0

BIN
.vs/MOTINOVA_Motor_Factory_Set/v16/.suo


+ 7 - 7
CheckForm.Designer.cs

@@ -241,7 +241,7 @@
             this.richTextBox_CfgFile.Location = new System.Drawing.Point(6, 31);
             this.richTextBox_CfgFile.Name = "richTextBox_CfgFile";
             this.richTextBox_CfgFile.ReadOnly = true;
-            this.richTextBox_CfgFile.Size = new System.Drawing.Size(238, 555);
+            this.richTextBox_CfgFile.Size = new System.Drawing.Size(253, 555);
             this.richTextBox_CfgFile.TabIndex = 1;
             this.richTextBox_CfgFile.Text = "";
             // 
@@ -332,7 +332,7 @@
             this.richTextBox_ReadCfg.Location = new System.Drawing.Point(6, 31);
             this.richTextBox_ReadCfg.Name = "richTextBox_ReadCfg";
             this.richTextBox_ReadCfg.ReadOnly = true;
-            this.richTextBox_ReadCfg.Size = new System.Drawing.Size(238, 555);
+            this.richTextBox_ReadCfg.Size = new System.Drawing.Size(253, 555);
             this.richTextBox_ReadCfg.TabIndex = 1;
             this.richTextBox_ReadCfg.Text = "";
             // 
@@ -363,9 +363,9 @@
             // 
             this.label_error_code.BackColor = System.Drawing.Color.Green;
             this.label_error_code.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
-            this.label_error_code.Location = new System.Drawing.Point(463, 151);
+            this.label_error_code.Location = new System.Drawing.Point(478, 151);
             this.label_error_code.Name = "label_error_code";
-            this.label_error_code.Size = new System.Drawing.Size(120, 30);
+            this.label_error_code.Size = new System.Drawing.Size(105, 30);
             this.label_error_code.TabIndex = 3;
             this.label_error_code.Text = "20000000H";
             this.label_error_code.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -375,7 +375,7 @@
             // 
             this.label1.AutoSize = true;
             this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
-            this.label1.Location = new System.Drawing.Point(486, 124);
+            this.label1.Location = new System.Drawing.Point(501, 124);
             this.label1.Name = "label1";
             this.label1.Size = new System.Drawing.Size(58, 21);
             this.label1.TabIndex = 0;
@@ -413,7 +413,7 @@
             this.groupBox5.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
             this.groupBox5.Location = new System.Drawing.Point(12, 103);
             this.groupBox5.Name = "groupBox5";
-            this.groupBox5.Size = new System.Drawing.Size(445, 86);
+            this.groupBox5.Size = new System.Drawing.Size(460, 86);
             this.groupBox5.TabIndex = 17;
             this.groupBox5.TabStop = false;
             this.groupBox5.Text = "操作";
@@ -450,7 +450,7 @@
             this.button_Start.ForeColor = System.Drawing.Color.White;
             this.button_Start.Location = new System.Drawing.Point(352, 21);
             this.button_Start.Name = "button_Start";
-            this.button_Start.Size = new System.Drawing.Size(87, 57);
+            this.button_Start.Size = new System.Drawing.Size(102, 57);
             this.button_Start.TabIndex = 17;
             this.button_Start.Text = "开始\r\n测试";
             this.button_Start.UseVisualStyleBackColor = false;

+ 48 - 46
CheckForm.cs

@@ -743,8 +743,7 @@ namespace MOTINOVA_Motor_Factory_Set
                 if (!File.Exists(LocalCfgFilePath + SelectFile))//检查本地是否存在选定文件
                 {
                     SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "/" + comboBox_File.SelectedItem.ToString();
-                    StartForm.myFtp.DownLoadNotReName(StartForm.myServerCfg.RootPath + "/cfg/" + SelectFile, LocalCfgFilePath + comboBox_cfgFileDate.SelectedItem.ToString());
-
+                    StartForm.myFtp.DownloadFile(StartForm.myServerCfg.RootPath + "/cfg/" + SelectFile, LocalCfgFilePath + comboBox_cfgFileDate.SelectedItem.ToString());
                 }
             }
             SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "\\" + comboBox_File.SelectedItem.ToString();
@@ -1137,21 +1136,21 @@ namespace MOTINOVA_Motor_Factory_Set
             LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\测试记录" + ".png";
             bit.Save(LogSaveFileName);
             //测试页面上传服务器
-            if (StartForm.myFtp.IsNetConnected == true)
-            {
-                string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow);
-                }
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow + "/" + ResultPathName) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
-                }
-                bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
-                if (result == true)
-                    richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
-            }
+            //if (StartForm.myFtp.IsNetConnected == true)
+            //{
+            //    string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow);
+            //    }
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow + "/" + ResultPathName) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
+            //    }
+            //    bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
+            //    if (result == true)
+            //        richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
+            //}
             //电机数据存储
             LogSaveFileName = LogSavePath + "\\log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\电机参数" + ".txt";
             string fileInfo = "";
@@ -1169,22 +1168,22 @@ namespace MOTINOVA_Motor_Factory_Set
             fileInfo += "测试结果:\r\n";
             fileInfo += label_Result.Text.Replace("\n", "\r\n") + "\r\n\r\n";
             System.IO.File.WriteAllText(LogSaveFileName, fileInfo);
-            //电机数据上传服务器
-            if (StartForm.myFtp.IsNetConnected == true)
-            {
-                string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow);
-                }
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow, ResultPathName) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
-                }
-                bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
-                if (result == true)
-                    richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机数据上传服务器成功" + "\r\n";
-            }
+            ////电机数据上传服务器
+            //if (StartForm.myFtp.IsNetConnected == true)
+            //{
+            //    string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow);
+            //    }
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow, ResultPathName) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
+            //    }
+            //    bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
+            //    if (result == true)
+            //        richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机数据上传服务器成功" + "\r\n";
+            //}
             #endregion
         }
 
@@ -1216,23 +1215,23 @@ namespace MOTINOVA_Motor_Factory_Set
             Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
             Graphics g = Graphics.FromImage(bit);
             g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片  
-            string LogSaveFileName = LogSavePath + "\\errorlog\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\";
+            string LogSaveFileName = LogSavePath + "errorlog\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\";
             if (System.IO.Directory.Exists(LogSaveFileName) == false)
                 System.IO.Directory.CreateDirectory(LogSaveFileName);
             LogSaveFileName += textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_测试记录" + ".png";
             bit.Save(LogSaveFileName);
             //测试页面上传服务器
-            if (StartForm.myFtp.IsNetConnected == true)
-            {
-                string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/errorlog/", DateNow) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/errorlog/" + DateNow);
-                }
-                bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/errorlog/" + DateNow);
-                if (result == true)
-                    richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常页面上传服务器成功" + "\r\n";
-            } 
+            //if (StartForm.myFtp.IsNetConnected == true)
+            //{
+            //    string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/errorlog/", DateNow) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/errorlog/" + DateNow);
+            //    }
+            //    bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/errorlog/" + DateNow);
+            //    if (result == true)
+            //        richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常页面上传服务器成功" + "\r\n";
+            //} 
         }
 
         //开始测试按钮点击
@@ -1290,7 +1289,7 @@ namespace MOTINOVA_Motor_Factory_Set
                     return;
                 }
             }
-            catch (System.Exception ex)
+            catch (System.Exception)
             {
                 label_Step.Text = "标签格式错误!";
                 label_Step.ForeColor = Color.Red;
@@ -1326,6 +1325,9 @@ namespace MOTINOVA_Motor_Factory_Set
             Thread th = new Thread(Thread_Task);
             th.Start();
 
+            //上传测试数据
+
+
         }
 
         //双击清零流水号

+ 1 - 1
ImportForm.Designer.cs

@@ -712,7 +712,7 @@
             this.label10.BackColor = System.Drawing.Color.White;
             this.label10.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.label10.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
-            this.label10.Location = new System.Drawing.Point(393, 80);
+            this.label10.Location = new System.Drawing.Point(393, 86);
             this.label10.Name = "label10";
             this.label10.Size = new System.Drawing.Size(75, 21);
             this.label10.TabIndex = 6;

+ 64 - 58
ImportForm.cs

@@ -162,7 +162,8 @@ namespace MOTINOVA_Motor_Factory_Set
                 if (!File.Exists(LocalCfgFilePath + SelectFile))//检查本地是否存在选定文件
                 {
                     SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "/" + comboBox_File.SelectedItem.ToString();
-                    StartForm.myFtp.DownLoadNotReName(StartForm.myServerCfg.RootPath + "/cfg/" + SelectFile, LocalCfgFilePath + comboBox_cfgFileDate.SelectedItem.ToString());
+
+                    StartForm.myFtp.DownloadFile(StartForm.myServerCfg.RootPath + "/cfg/" + SelectFile, LocalCfgFilePath + comboBox_cfgFileDate.SelectedItem.ToString());
 
                 }
             }
@@ -394,7 +395,12 @@ namespace MOTINOVA_Motor_Factory_Set
                                 //数据存储
                                 var RecData = new byte[CmdLen];
                                 Array.Copy(binary_data_1, RecData, CmdLen);
-                                DataSave(RecData);
+                                if ((PackageID == 0x0710) || (PackageID == 0x0715) ||
+                                   (PackageID == 0x0610) || (PackageID == 0x0615) ||
+                                   (PackageID == 0x07FF))
+                                { 
+                                    DataSave(RecData);
+                                }
                             }
                             DataCmdProcess(PackageID);//对于不同的命令段,做不同的处理                          
                         }
@@ -902,17 +908,17 @@ namespace MOTINOVA_Motor_Factory_Set
             LogSaveFileName += textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_测试记录" + ".png";
             bit.Save(LogSaveFileName);
             //测试页面上传服务器
-            if (StartForm.myFtp.IsNetConnected == true)
-            {
-                string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/errorlog/", DateNow) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/errorlog/" + DateNow);
-                }
-                bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/errorlog/" + DateNow);
-                if (result == true)
-                    richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常页面上传服务器成功" + "\r\n";
-            }
+            //if (StartForm.myFtp.IsNetConnected == true)
+            //{
+            //    string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/errorlog/", DateNow) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/errorlog/" + DateNow);
+            //    }
+            //    bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/errorlog/" + DateNow);
+            //    if (result == true)
+            //        richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常页面上传服务器成功" + "\r\n";
+            //}
                 
         }
 
@@ -2035,21 +2041,21 @@ namespace MOTINOVA_Motor_Factory_Set
             button_Start.Enabled = true;
 
             //导出的参数上传服务器
-            if (StartForm.myFtp.IsNetConnected == true)
-            {
-                string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
-                }
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
-                }
-                bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
-                if (result == true)
-                    richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机配置参数上传服务器成功" + "\r\n";
-            }
+            //if (StartForm.myFtp.IsNetConnected == true)
+            //{
+            //    string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
+            //    }
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
+            //    }
+            //    bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
+            //    if (result == true)
+            //        richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机配置参数上传服务器成功" + "\r\n";
+            //}
 
             //保存测试信息
             //页面存储
@@ -2059,41 +2065,41 @@ namespace MOTINOVA_Motor_Factory_Set
             LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\测试页面" + ".png";
             bit.Save(LogSaveFileName);
             //测试页面上传服务器
-            if(StartForm.myFtp.IsNetConnected==true)
-            {
-                string DateNow = DateTime.Now.ToString("yyyy-MM-dd"); 
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
-                }
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
-                }
-                bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
-                if (result == true)
-                    richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
-            }
+            //if(StartForm.myFtp.IsNetConnected==true)
+            //{
+            //    string DateNow = DateTime.Now.ToString("yyyy-MM-dd"); 
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
+            //    }
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
+            //    }
+            //    bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
+            //    if (result == true)
+            //        richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
+            //}
 
             //保存测试记录
             LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\测试记录" + ".txt";
             richTextBox_TestRecord.SaveFile(LogSaveFileName, RichTextBoxStreamType.PlainText);
             //测试记录上传服务器
-            if (StartForm.myFtp.IsNetConnected == true)
-            {
-                string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
-                }
-                if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
-                {
-                    StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
-                }
-                bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
-                if (result == true)
-                    richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
-            }
+            //if (StartForm.myFtp.IsNetConnected == true)
+            //{
+            //    string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
+            //    }
+            //    if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
+            //    {
+            //        StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
+            //    }
+            //    bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
+            //    if (result == true)
+            //        richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
+            //}
         }
 
         //开始测试

+ 3 - 1
MOTINOVA_Motor_Factory_Set.csproj

@@ -8,10 +8,11 @@
     <OutputType>WinExe</OutputType>
     <RootNamespace>MOTINOVA_Motor_Factory_Set</RootNamespace>
     <AssemblyName>MOTINOVA_Motor_Factory_Set</AssemblyName>
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <Deterministic>true</Deterministic>
     <IsWebBootstrapper>false</IsWebBootstrapper>
+    <TargetFrameworkProfile />
     <PublishUrl>D:\SoftDesign\MOTINOVA_Motor_Factory_Set\</PublishUrl>
     <Install>true</Install>
     <InstallFrom>Disk</InstallFrom>
@@ -153,6 +154,7 @@
     <EmbeddedResource Include="StartForm.resx">
       <DependentUpon>StartForm.cs</DependentUpon>
     </EmbeddedResource>
+    <None Include="app.config" />
     <None Include="MOTINOVA_Motor_Factory_Set_TemporaryKey.pfx" />
     <None Include="Properties\app.manifest" />
     <None Include="Properties\Settings.settings">

+ 13 - 17
Properties/Settings.Designer.cs

@@ -1,28 +1,24 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
-//     This code was generated by a tool.
-//     Runtime Version:4.0.30319.42000
+//     此代码由工具生成。
+//     运行时版本:4.0.30319.42000
 //
-//     Changes to this file may cause incorrect behavior and will be lost if
-//     the code is regenerated.
+//     对此文件的更改可能会导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
 // </auto-generated>
 //------------------------------------------------------------------------------
 
-namespace MOTINOVA_Motor_Factory_Set.Properties
-{
-
-
+namespace MOTINOVA_Motor_Factory_Set.Properties {
+    
+    
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
-    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
-    {
-
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.7.0.0")]
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+        
         private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
-        public static Settings Default
-        {
-            get
-            {
+        
+        public static Settings Default {
+            get {
                 return defaultInstance;
             }
         }

+ 2 - 2
StartForm.Designer.cs

@@ -123,9 +123,9 @@
             // label_NetStatus
             // 
             this.label_NetStatus.ForeColor = System.Drawing.Color.Red;
-            this.label_NetStatus.Location = new System.Drawing.Point(623, 497);
+            this.label_NetStatus.Location = new System.Drawing.Point(477, 497);
             this.label_NetStatus.Name = "label_NetStatus";
-            this.label_NetStatus.Size = new System.Drawing.Size(157, 21);
+            this.label_NetStatus.Size = new System.Drawing.Size(303, 21);
             this.label_NetStatus.TabIndex = 2;
             this.label_NetStatus.Text = "网络连接中……";
             this.label_NetStatus.TextAlign = System.Drawing.ContentAlignment.MiddleRight;

+ 173 - 11
StartForm.cs

@@ -1,12 +1,10 @@
 using System;
 using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
 using System.Drawing;
-using System.Text;
 using System.Windows.Forms;
 using System.Threading;
 using System.IO;
+using System.Linq;
 
 namespace MOTINOVA_Motor_Factory_Set
 {
@@ -76,11 +74,11 @@ namespace MOTINOVA_Motor_Factory_Set
             {
                 if (Result == true)//服务器连接成功
                 {
-                    label_NetStatus.Text = "网络连接成功";
+                    label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
                     label_NetStatus.ForeColor = Color.Green;
-                    ImportForm1.label_NetStatus.Text = "网络连接成功";
+                    ImportForm1.label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
                     ImportForm1.label_NetStatus.BackColor = Color.Green;
-                    CheckForm1.label_NetStatus.Text = "网络连接成功";
+                    CheckForm1.label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
                     CheckForm1.label_NetStatus.BackColor = Color.Green;
                     if (myServerCfg.Local == "DISABLE")//不允许本地文件
                     {
@@ -131,10 +129,10 @@ namespace MOTINOVA_Motor_Factory_Set
                 button_Mang.Enabled = true;
                 button_Check.Enabled = true;
             }));
-            //创建定时器,定时3s检查网络
+            //创建定时器,定时10s检查网络
             System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
             timer_CheckNet.Enabled = true;
-            timer_CheckNet.Interval = 3000;
+            timer_CheckNet.Interval = 10000;
             timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
             timer_CheckNet.Start();
             while (true)
@@ -152,11 +150,11 @@ namespace MOTINOVA_Motor_Factory_Set
             {
                 if (Result == true)//服务器连接成功
                 {
-                    label_NetStatus.Text = "网络连接成功";
+                    label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
                     label_NetStatus.ForeColor = Color.Green;
-                    ImportForm1.label_NetStatus.Text = "网络连接成功";
+                    ImportForm1.label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
                     ImportForm1.label_NetStatus.BackColor = Color.Green;
-                    CheckForm1.label_NetStatus.Text = "网络连接成功";
+                    CheckForm1.label_NetStatus.Text = myServerCfg.ServerName + " | " + myServerCfg.IP + " | " + "连接成功";
                     CheckForm1.label_NetStatus.BackColor = Color.Green;
                     if (myServerCfg.Local == "DISABLE")//不允许本地文件
                     {
@@ -170,6 +168,20 @@ namespace MOTINOVA_Motor_Factory_Set
                     }
  
                     myFtp.IsNetConnected = true;
+
+                    //定时与服务器同步文件
+#if true
+                    //cfg
+                    PathSyncWithServer("/cfg");
+                    //qcTest/errorlog
+                    PathSyncWithServer("/qcTest/errorlog");
+                    //qcTest/log
+                    PathSyncWithServer("/qcTest/log");
+                    //walkTest/errorlog
+                    PathSyncWithServer("/walkTest/errorlog");
+                    //walkTest/log
+                    PathSyncWithServer("/walkTest/log");
+#endif
                 }
                 else//服务器连接失败
                 {
@@ -188,6 +200,156 @@ namespace MOTINOVA_Motor_Factory_Set
             }));
         }
 
+        /// <summary>
+        /// 获取本地和远端目录名差集,本地有但远端没有
+        /// </summary>
+        /// <param name="localPath">本地路径</param>
+        /// <param name="remotePath">远端路径</param>
+        /// <returns>差集文件夹名称集合</returns>
+        private string[] FiltDiffDirectory(string localPath, string remotePath)
+        {
+            try
+            {
+                string[] Local = System.IO.Directory.GetDirectories(localPath);
+                for (int i = 0; i < Local.Length; i++)
+                    Local[i] = Local[i].Substring(Local[i].LastIndexOf("\\") + 1);
+                string[] Remote = StartForm.myFtp.GetDirectoryList(remotePath);
+                for (int i = 0; i < Remote.Length; i++)
+                    Remote[i] = Remote[i].Substring(Remote[i].LastIndexOf("/") + 1);
+                return Local.Except(Remote).ToList().ToArray();
+            }
+            catch (Exception ex)
+            { 
+                throw new Exception("同步失败,原因: " + ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 获取本地和远端文件夹下目录名交集
+        /// </summary>
+        /// <param name="localPath"></param>
+        /// <param name="remotePath"></param>
+        /// <returns></returns>
+        private string[] FiltCommonDirectory(string localPath, string remotePath)
+        {
+            try
+            {
+                string[] Local = System.IO.Directory.GetDirectories(localPath);
+                for (int i = 0; i < Local.Length; i++)
+                    Local[i] = Local[i].Substring(Local[i].LastIndexOf("\\") + 1);
+                string[] Remote = StartForm.myFtp.GetDirectoryList(remotePath);
+                for (int i = 0; i < Remote.Length; i++)
+                    Remote[i] = Remote[i].Substring(Remote[i].LastIndexOf("/") + 1);
+                return Local.Intersect(Remote).ToList().ToArray();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("同步失败,原因: " + ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 获取本地和远端文件名差集,本地存在而远端不存在
+        /// </summary>
+        /// <param name="localPath">本地路径</param>
+        /// <param name="remotePath">远端路径</param>
+        /// <returns>差集文件名集合</returns>
+        private string[] FiltDiffFiles(string localPath, string remotePath)
+        {
+            try
+            {
+                string[] Local = System.IO.Directory.GetFiles(localPath);
+                for (int i = 0; i < Local.Length; i++)
+                    Local[i] = Local[i].Substring(Local[i].LastIndexOf("\\") + 1);
+                string[] Remote = StartForm.myFtp.GetFileNameList(remotePath);
+                for (int i = 0; i < Remote.Length; i++)
+                    Remote[i] = Remote[i].Substring(Remote[i].LastIndexOf("/") + 1);
+                return Local.Except(Remote).ToList().ToArray();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("同步失败,原因: " + ex.Message);
+            }
+        }
+
+        /// <summary>
+        ///  获取本地和远端文件名交集
+        /// </summary>
+        /// <param name="localPath"></param>
+        /// <param name="remotePath"></param>
+        /// <returns></returns>
+        private string[] FiltCommonFiles(string localPath, string remotePath)
+        {
+            try
+            {
+                string[] Local = System.IO.Directory.GetFiles(localPath);
+                for (int i = 0; i < Local.Length; i++)
+                    Local[i] = Local[i].Substring(Local[i].LastIndexOf("\\") + 1);
+                string[] Remote = StartForm.myFtp.GetFileNameList(remotePath);
+                for (int i = 0; i < Remote.Length; i++)
+                    Remote[i] = Remote[i].Substring(Remote[i].LastIndexOf("/") + 1);
+                return Local.Intersect(Remote).ToList().ToArray();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("同步失败,原因: " + ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 同步本地和远端文件夹
+        /// 本地有、远端无的文件夹,上传该目录下本地所有文件
+        /// 本地有和远端有的文件夹,上传本地有但远端没有的文件
+        /// </summary>
+        /// <param name="PathName"></param>
+        /// <returns></returns>
+        private void PathSyncWithServer(string PathName)
+        {
+            List<string> pathResult = null;
+
+            //获取本地和远端的目录差集
+            pathResult = FiltDiffDirectory(UserPath + PathName, myServerCfg.RootPath + PathName).ToList();
+            if (pathResult.Count != 0)
+            {
+                foreach (string path in pathResult)
+                {
+                    //远端建立文件夹
+                    myFtp.MakeDir(myServerCfg.RootPath + PathName + "/" + path);
+                    //获取待上传文件列表
+                    string[] fileList = Directory.GetFiles(UserPath + PathName + "\\" + path);
+                    for (int i = 0; i < fileList.Length; i++)
+                        fileList[i] = fileList[i].Substring(fileList[i].LastIndexOf("\\") + 1);
+                    //上传文件
+                    if (fileList.Length != 0)
+                    {
+                        foreach (string file in fileList)
+                        {
+                            myFtp.UploadFile(UserPath + PathName + "\\" + path + "\\" + file, myServerCfg.RootPath + PathName + "/" + path);
+                        }
+                    }
+                }
+            }
+
+            //获取本地和远端的目录交集
+            pathResult = FiltCommonDirectory(UserPath + PathName, myServerCfg.RootPath + PathName).ToList();
+            if (pathResult.Count != 0)
+            {
+                foreach (string path in pathResult)
+                {
+                    //获取该目录本地和远端文件名的差集,本地有但远端无
+                    string[] fileList = FiltDiffFiles(UserPath + PathName + "\\" + path, myServerCfg.RootPath + PathName + "/" + path);
+                    //上传文件
+                    if (fileList.Length != 0)
+                    {
+                        foreach (string file in fileList)
+                        {
+                            myFtp.UploadFile(UserPath + PathName + "\\" + path + "\\" + file, myServerCfg.RootPath + PathName + "/" + path);
+                        }
+                    }
+                }
+            }
+
+        }
         
         private void button_Import_Click(object sender, EventArgs e)
         {

+ 2 - 2
bin/Debug/MOTINOVA_Motor_Factory_Set.application

@@ -4,14 +4,14 @@
   <description asmv2:publisher="Microsoft" asmv2:product="MOTINOVA_Motor_Factory_Set" xmlns="urn:schemas-microsoft-com:asm.v1" />
   <deployment install="true" mapFileExtensions="true" />
   <dependency>
-    <dependentAssembly dependencyType="install" codebase="MOTINOVA_Motor_Factory_Set.exe.manifest" size="4087">
+    <dependentAssembly dependencyType="install" codebase="MOTINOVA_Motor_Factory_Set.exe.manifest" size="5061">
       <assemblyIdentity name="MOTINOVA_Motor_Factory_Set.exe" version="1.0.0.1" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
       <hash>
         <dsig:Transforms>
           <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
         </dsig:Transforms>
         <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
-        <dsig:DigestValue>8lkjG1Zwi0WZnf+1KglST0n7rIY=</dsig:DigestValue>
+        <dsig:DigestValue>e33NI0rEEmrhGT4OMhFr0rOkPZ0=</dsig:DigestValue>
       </hash>
     </dependentAssembly>
   </dependency>

BIN
bin/Debug/MOTINOVA_Motor_Factory_Set.exe


+ 22 - 3
bin/Debug/MOTINOVA_Motor_Factory_Set.exe.manifest

@@ -31,7 +31,7 @@
   <dependency>
     <dependentOS>
       <osVersionInfo>
-        <os majorVersion="4" minorVersion="10" buildNumber="0" servicePackMajor="0" />
+        <os majorVersion="5" minorVersion="1" buildNumber="2600" servicePackMajor="0" />
       </osVersionInfo>
     </dependentOS>
   </dependency>
@@ -41,17 +41,36 @@
     </dependentAssembly>
   </dependency>
   <dependency>
-    <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="MOTINOVA_Motor_Factory_Set.exe" size="624032">
+    <dependentAssembly dependencyType="preRequisite" allowDelayedBinding="true">
+      <assemblyIdentity name="System.Core" version="3.5.0.0" publicKeyToken="b77a5c561934e089" language="neutral" processorArchitecture="msil" />
+    </dependentAssembly>
+  </dependency>
+  <dependency>
+    <dependentAssembly dependencyType="preRequisite" allowDelayedBinding="true">
+      <assemblyIdentity name="WindowsBase" version="3.0.0.0" publicKeyToken="31bf3856ad364e35" language="neutral" processorArchitecture="msil" />
+    </dependentAssembly>
+  </dependency>
+  <dependency>
+    <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="MOTINOVA_Motor_Factory_Set.exe" size="625568">
       <assemblyIdentity name="MOTINOVA_Motor_Factory_Set" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
       <hash>
         <dsig:Transforms>
           <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
         </dsig:Transforms>
         <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
-        <dsig:DigestValue>ZNs+1N2BDSXC8XXi4JDfnVzNov0=</dsig:DigestValue>
+        <dsig:DigestValue>aHi3NOi2hW+smAUr8XKyhB65JjI=</dsig:DigestValue>
       </hash>
     </dependentAssembly>
   </dependency>
+  <file name="MOTINOVA_Motor_Factory_Set.exe.config" size="134">
+    <hash>
+      <dsig:Transforms>
+        <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
+      </dsig:Transforms>
+      <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
+      <dsig:DigestValue>ZYVCbF014jyazUw+0nEkH92/ao4=</dsig:DigestValue>
+    </hash>
+  </file>
   <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
     <application>
       <!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的

BIN
bin/Debug/MOTINOVA_Motor_Factory_Set.pdb


+ 1 - 1
bin/Debug/SerialNum

@@ -1,2 +1,2 @@
 流水号:
-231
+298

+ 18 - 7
bin/Debug/Server

@@ -1,10 +1,4 @@
-IP=192.168.1.74
-PORT=21
-USER=factory_test
-PASSWD=ttium
-ROOT=MOTINOVA_MC_Factory_Set
-LOCAL=ENABLE
-
+#阿里云
 IP=47.105.122.91
 PORT=21
 USER=ftptest
@@ -12,6 +6,23 @@ PASSWD=123456
 ROOT=/home/ftptest
 LOCAL=ENABLE
 
+#百度云
+IP=180.76.154.142
+PORT=21
+USER=dail
+PASSWD=1229
+ROOT=/home/dail/Factory_Test
+LOCAL=ENABLE
+
+#内部服务器
+IP=192.168.1.74
+PORT=21
+USER=factory_test
+PASSWD=ttium
+ROOT=MOTINOVA_MC_Factory_Set
+LOCAL=ENABLE
+
+#虚拟机
 IP=192.168.1.246
 PORT=21
 USER=hero

BIN
bin/Debug/app.publish/MOTINOVA_Motor_Factory_Set.exe


+ 217 - 91
ftp.cs

@@ -8,14 +8,19 @@ namespace MOTINOVA_Motor_Factory_Set
 {
     public class ftp
     {
-        #region
-
         string serverIP;
         string serverPort;
         string userId;
         string passWord;
         public bool IsNetConnected = false;
 
+        /// <summary>
+        /// 配置网络
+        /// </summary>
+        /// <param name="serverIP"></param>
+        /// <param name="serverPort"></param>
+        /// <param name="userId"></param>
+        /// <param name="passWord"></param>
         public void FtpOption(string serverIP, string serverPort, string userId, string passWord)
         {
             this.serverIP = serverIP;
@@ -24,6 +29,10 @@ namespace MOTINOVA_Motor_Factory_Set
             this.passWord = passWord;
         }
 
+        /// <summary>
+        /// 检查网络
+        /// </summary>
+        /// <returns>bool</returns>
         public bool CheckFtp()
         {
             try
@@ -32,143 +41,185 @@ namespace MOTINOVA_Motor_Factory_Set
                 FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(uri);
                 ftpRequest.Credentials = new NetworkCredential(userId, passWord);
                 ftpRequest.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
-                ftpRequest.Timeout = 2000;
                 FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                 ftpResponse.Close();
                 IsNetConnected = true;
                 return true;
             }
-            catch (Exception ex)
+            catch (Exception)
             {
                 IsNetConnected = false;
                 return false;
             }
-
         }
 
-        private FtpWebRequest OpenRequest(Uri uri, string ftpMethord)
+        /// <summary>
+        /// 文件上传
+        /// </summary>
+        /// <param name="sourceFullPath">要上传文件全名</param>
+        /// <param name="targetPath">服务器端地址(temp)</param>
+        /// <returns></returns>
+        public bool UploadFile(string sourceFullPath, string targetPath)
         {
-            try
-            {
-                FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(uri);
-                ftpRequest.Credentials = new NetworkCredential(userId, passWord);
-                ftpRequest.Method = ftpMethord;
-                ftpRequest.UseBinary = true;
-                return ftpRequest;
-            }
-            catch (Exception ex)
+            FtpWebRequest reqFTP = null;
+            FileStream fs = null;
+            Stream strm = null;
+
+            FileInfo fileInf = new FileInfo(sourceFullPath);
+            string fileName = sourceFullPath.Substring(sourceFullPath.LastIndexOf("\\") + 1);
+
+            //远端存在该文件时,先删除
+            if (FileExist(targetPath, fileName))
             {
-                throw ex;
+                DeleteFile(targetPath + "/" + fileName);
             }
-        }
-        private FtpWebResponse OpenResponse(Uri uri, string ftpMethord)
-        {
+
+            Uri uri = new Uri("ftp://" + serverIP + ":" + serverPort + "/" + targetPath + "/" + Uri.EscapeDataString(fileName));
+            reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
+            reqFTP.Credentials = new NetworkCredential(userId, passWord);
+            reqFTP.KeepAlive = false;
+            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
+            reqFTP.UseBinary = true;
+            reqFTP.UsePassive = false;
+            reqFTP.ContentLength = fileInf.Length;
+            byte[] buff = new byte[2048];
+            int contentLen = 0;
+            fs = fileInf.OpenRead();
             try
             {
-                return this.OpenRequest(uri, ftpMethord).GetResponse() as FtpWebResponse;
+                strm = reqFTP.GetRequestStream();
+                while ((contentLen = fs.Read(buff, 0, buff.Length)) != 0)
+                {
+                    strm.Write(buff, 0, contentLen);
+                }
+                fs.Close();
+                strm.Close();
+                return true;
             }
-            catch
+            catch (Exception ex)
             {
-                throw new Exception("登录到Ftp服务器失败!");
+                fs.Close();
+                strm.Close();
+                throw new Exception("上传文件失败,原因: " + ex.Message);
             }
         }
 
-        #endregion
-
         /// <summary>
-        /// 下载(重命名)
+        /// 文件下载
         /// </summary>
-        /// <param name="sourceFullPath">下载文件全路径</param>
-        /// <param name="targetFullPath">下载到本机全路径(包含文件名)</param>
-        /// <returns></returns>
-        public bool DownLoadReName(string sourceFullPath, string targetFullPath)
+        /// <param name="filePath">文件本地存放路径</param>
+        /// <param name="serverPath">远端文件路径</param>
+        /// <param name="fileName">文件名</param>
+        /// <returns>bool</returns>
+        public bool DownloadFile(string sourceFullPath, string targetFullPath)
         {
+            FtpWebRequest ftpRequest = null;
+            FileStream outputStream = null;
+            FtpWebResponse response = null;
+            Stream ftpStream = null;
+
             try
             {
+                string fileName = sourceFullPath.Substring(sourceFullPath.LastIndexOf("/"));
+                outputStream = new FileStream(targetFullPath + fileName, FileMode.Create);
                 Uri uri = new Uri("ftp://" + serverIP + "/" + sourceFullPath);
-                FtpWebResponse downloadResponse = OpenResponse(uri, WebRequestMethods.Ftp.DownloadFile);
-                Stream responseStream = downloadResponse.GetResponseStream();
-                FileStream fileStream = File.Create(targetFullPath);
-                byte[] buffer = new byte[1024];
-                int bytesRead = 0;
-                while (true)
+                ftpRequest = (FtpWebRequest)FtpWebRequest.Create(uri);
+                ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
+                ftpRequest.UseBinary = true;
+                ftpRequest.UsePassive = false;
+                ftpRequest.Proxy = null;
+                ftpRequest.Credentials = new NetworkCredential(userId, passWord);
+                response = (FtpWebResponse)ftpRequest.GetResponse();
+                ftpStream = response.GetResponseStream();
+                int readCount = 0;
+                byte[] buffer = new byte[2048];
+
+                while ((readCount = ftpStream.Read(buffer, 0, buffer.Length)) > 0)
                 {
-                    bytesRead = responseStream.Read(buffer, 0, buffer.Length);
-                    if (bytesRead == 0)
-                        break;
-                    fileStream.Write(buffer, 0, bytesRead);
+                    outputStream.Write(buffer, 0, readCount);
                 }
-                fileStream.Close();
-                responseStream.Close();
+                outputStream.Close();
+                ftpStream.Close();
+                response.Close();
                 return true;
             }
-            catch
+            catch (Exception ex)
             {
-                throw new Exception("获取下载文件失败!");
+                outputStream.Close();
+                ftpStream.Close();
+                response.Close();
+                throw new Exception("下载文件失败,原因: " + ex.Message);
             }
         }
 
         /// <summary>
-        /// 下载(按原名直接)
-        /// </summary> www.jbxue.com
-        /// <param name="loadFullPath">下载文件的全路径</param>
-        /// <param name="targePath">下载到指定的地址(E:/)</param>
-        /// <returns></returns>
-        public bool DownLoadNotReName(string sourceFullPath, string targePath)
+        /// 删除文件
+        /// </summary>
+        /// <param name="fileName"></param>
+        public void DeleteFile(string fileName)
         {
             try
             {
-                string fileName = sourceFullPath.Substring(sourceFullPath.LastIndexOf("/"));
-                if (!Directory.Exists(targePath))//不存在就创建文件夹
-                {
-                    Directory.CreateDirectory(targePath);
-                }
-                return DownLoadReName(sourceFullPath, targePath + fileName);
+                Uri uri = new Uri("ftp://" + serverIP + "/" + fileName);
+                FtpWebRequest reqFTP;
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
+
+                reqFTP.Credentials = new NetworkCredential(userId, passWord);
+                reqFTP.KeepAlive = false;
+                reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;
+                reqFTP.UsePassive = false;
+
+                string result = String.Empty;
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                long size = response.ContentLength;
+                Stream datastream = response.GetResponseStream();
+                StreamReader sr = new StreamReader(datastream);
+                result = sr.ReadToEnd();
+                sr.Close();
+                datastream.Close();
+                response.Close();
             }
             catch (Exception ex)
             {
-                throw ex;
+                throw new Exception("文件删除失败!" + ex.Message);
             }
         }
 
         /// <summary>
-        /// 文件上传
+        /// 删除文件夹
         /// </summary>
-        /// <param name="sourceFullPath">要上传文件的地址(G:/Ftp.txt)</param>
-        /// <param name="targetPath">服务器端地址(temp)</param>
-        /// <returns></returns>
-        public bool UploadFile(string sourceFullPath, string targetPath)
+        /// <param name="folderName"></param>
+        public void RemoveDirectory(string folderName)
         {
             try
             {
-                string fileName = sourceFullPath.Substring(sourceFullPath.LastIndexOf("\\") + 1);
-                //检查路径
-                Uri uri = new Uri("ftp://" + serverIP + ":" + serverPort + "/" + targetPath + "/" + Uri.EscapeDataString(fileName));
-                FtpWebRequest request = this.OpenRequest(uri, WebRequestMethods.Ftp.UploadFile);
-                Stream requestStream = request.GetRequestStream();
-                FileStream fileStream = new System.IO.FileStream(sourceFullPath, FileMode.Open);
-                byte[] buffer = new byte[2048];
-                int bytesRead;
-                while (true)
-                {
-                    bytesRead = fileStream.Read(buffer, 0, buffer.Length);
-                    if (bytesRead == 0)
-                        break;
-                    requestStream.Write(buffer, 0, bytesRead);
-                }
-                requestStream.Close();
-                request.GetResponse();
-                fileStream.Close();
-                return true;
+                Uri uri = new Uri("ftp://" + serverIP + "/" + folderName);
+                FtpWebRequest reqFTP;
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
+
+                reqFTP.Credentials = new NetworkCredential(userId, passWord);
+                reqFTP.KeepAlive = false;
+                reqFTP.Method = WebRequestMethods.Ftp.RemoveDirectory;
+                reqFTP.UsePassive = false;
+
+                string result = String.Empty;
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                long size = response.ContentLength;
+                Stream datastream = response.GetResponseStream();
+                StreamReader sr = new StreamReader(datastream);
+                result = sr.ReadToEnd();
+                sr.Close();
+                datastream.Close();
+                response.Close();
             }
-            catch (Exception)
+            catch (Exception ex)
             {
-                return false;
+                throw new Exception("文件夹删除失败!" + ex.Message);
             }
         }
 
         /// <summary>
-        /// 获取目录文件详细信息
+        /// 获取当前目录下明细(包含文件和文件夹)
         /// </summary>
         /// <param name="ServerPath">远端的地址</param>
         /// <param name="WRMethods">
@@ -176,13 +227,21 @@ namespace MOTINOVA_Motor_Factory_Set
         /// 
         private string[] GetFileList(string ServerPath, string WRMethods)
         {
-            StringBuilder result = new StringBuilder();
+            StringBuilder result = null;
+            FtpWebRequest ftp = null;
+            WebResponse response = null;
+            StreamReader reader = null;
+
             try
             {
+                result = new StringBuilder();
                 Uri uri = new Uri("ftp://" + serverIP + "/" + ServerPath);
-                FtpWebResponse downloadResponse = OpenResponse(uri, WRMethods);
-                Stream responseStream = downloadResponse.GetResponseStream();
-                StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.Default);
+                ftp = (FtpWebRequest)FtpWebRequest.Create(uri);
+                ftp.Credentials = new NetworkCredential(userId,passWord);
+                ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
+                ftp.UsePassive = false;
+                response = ftp.GetResponse();
+                reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
                 string line = reader.ReadLine();
                 while (line != null)
                 {
@@ -195,7 +254,7 @@ namespace MOTINOVA_Motor_Factory_Set
                     result.Remove(result.ToString().LastIndexOf("\n"), 1);
                 }
                 reader.Close();
-                downloadResponse.Close();
+                response.Close();
                 return result.ToString().Split('\n');
             }
             catch (Exception ex)
@@ -241,7 +300,7 @@ namespace MOTINOVA_Motor_Factory_Set
         }
 
         /// <summary>
-        /// 获得文件明晰
+        /// 获取文件夹下明细
         /// </summary>
         /// <param name="path"></param>
         /// <returns></returns>
@@ -306,17 +365,47 @@ namespace MOTINOVA_Motor_Factory_Set
             return false;
         }
 
+        /// <summary>
+        /// 判断目录下指定的文件是否存在
+        /// </summary>
+        /// <param name="rootDir">远端目录</param>
+        /// <param name="fileName">指定文件</param>
+        /// <returns></returns>
+        public bool FileExist(string rootDir, string fileName)
+        {
+            string[] fileList = GetFileNameList(rootDir);
+            if (fileList.Length > 0)
+            {
+                foreach (string file in fileList)
+                {
+                    if (file.Substring(file.LastIndexOf("/") + 1) == fileName)
+                    {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
         /// <summary>
         /// 创建目录
         /// </summary>
         /// <param name="dirName"></param>
         public void MakeDir(string dirName)
         {
+            FtpWebRequest reqFTP;
             try
             {
                 Uri uri = new Uri("ftp://" + serverIP + "/" + dirName);
-                FtpWebResponse downloadResponse = OpenResponse(uri, WebRequestMethods.Ftp.MakeDirectory);
-                downloadResponse.Close();
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
+                reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;
+                reqFTP.UseBinary = true;
+                reqFTP.UsePassive = false;
+                reqFTP.Credentials = new NetworkCredential(userId,passWord);
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                Stream ftpStream = response.GetResponseStream();
+                ftpStream.Close();
+                response.Close();
             }
             catch (Exception ex)
             {
@@ -324,7 +413,44 @@ namespace MOTINOVA_Motor_Factory_Set
             }
         }
 
+        /// <summary>
+        /// 重命名
+        /// </summary>
+        /// <param name="currentFilename"></param>
+        /// <param name="newFilename"></param>
+        public void ReName(string currentFilename, string newFilename)
+        {
+            FtpWebRequest reqFTP;
+            try
+            {
+                Uri uri = new Uri("ftp://" + serverIP + "/" + currentFilename);
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
+                reqFTP.Method = WebRequestMethods.Ftp.Rename;
+                reqFTP.RenameTo = newFilename;
+                reqFTP.UseBinary = true;
+                reqFTP.UsePassive = false;
+                reqFTP.Credentials = new NetworkCredential(userId,passWord);
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                Stream ftpStream = response.GetResponseStream();
+
+                ftpStream.Close();
+                response.Close();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("FtpHelper ReName Error --> " + ex.Message);
+            }
+        }
 
+        /// <summary>
+        /// 移动文件
+        /// </summary>
+        /// <param name="currentFilename"></param>
+        /// <param name="newFilename"></param>
+        public void MovieFile(string currentFilename, string newDirectory)
+        {
+            ReName(currentFilename, newDirectory);
+        }
 
     }
 }

BIN
obj/Debug/DesignTimeResolveAssemblyReferences.cache


BIN
obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache


+ 1 - 1
obj/Debug/MOTINOVA_Motor_Factory_Set.csproj.CoreCompileInputs.cache

@@ -1 +1 @@
-94cd8bad1de510b5b5ce4fb5640c228aad71f97b
+516a3fd09b4b85eee312342de542662aedfbd129

+ 1 - 0
obj/Debug/MOTINOVA_Motor_Factory_Set.csproj.FileListAbsolute.txt

@@ -18,3 +18,4 @@ D:\SoftDesign\MOTINOVA_Motor_Factory_Set\MOTINOVA_Motor_Factory_Set\obj\Debug\MO
 D:\SoftDesign\MOTINOVA_Motor_Factory_Set\MOTINOVA_Motor_Factory_Set\obj\Debug\MOTINOVA_Motor_Factory_Set.pdb
 D:\SoftDesign\MOTINOVA_Motor_Factory_Set\MOTINOVA_Motor_Factory_Set\obj\Debug\MOTINOVA_Motor_Factory_Set.CheckForm.resources
 D:\SoftDesign\MOTINOVA_Motor_Factory_Set\MOTINOVA_Motor_Factory_Set\obj\Debug\MOTINOVA_Motor_Factory_Set.Enter.resources
+D:\SoftDesign\MOTINOVA_Motor_Factory_Set\MOTINOVA_Motor_Factory_Set\bin\Debug\MOTINOVA_Motor_Factory_Set.exe.config

BIN
obj/Debug/MOTINOVA_Motor_Factory_Set.csproj.GenerateResource.cache


BIN
obj/Debug/MOTINOVA_Motor_Factory_Set.csprojAssemblyReference.cache


BIN
obj/Debug/MOTINOVA_Motor_Factory_Set.exe


BIN
obj/Debug/MOTINOVA_Motor_Factory_Set.pdb


BIN
obj/Debug/TempPE/Properties.Resources.Designer.cs.dll


+ 8 - 6
server_cfg.cs

@@ -7,6 +7,7 @@ namespace MOTINOVA_Motor_Factory_Set
 {
     public class server_cfg
     {
+        public string ServerName;
         public string IP;
         public string Port;
         public string User;
@@ -27,12 +28,13 @@ namespace MOTINOVA_Motor_Factory_Set
             }
             objReader.Close();
             //设定服务器配置
-            IP = array_CfgInfo[0].Substring(array_CfgInfo[0].LastIndexOf("=") + 1);
-            Port = array_CfgInfo[1].Substring(array_CfgInfo[1].LastIndexOf("=") + 1);
-            User = array_CfgInfo[2].Substring(array_CfgInfo[2].LastIndexOf("=") + 1);
-            PassWd = array_CfgInfo[3].Substring(array_CfgInfo[3].LastIndexOf("=") + 1);
-            RootPath = array_CfgInfo[4].Substring(array_CfgInfo[4].LastIndexOf("=") + 1);
-            Local = array_CfgInfo[5].Substring(array_CfgInfo[5].LastIndexOf("=") + 1);
+            ServerName = array_CfgInfo[0].Substring(array_CfgInfo[0].IndexOf("#") + 1);
+            IP = array_CfgInfo[1].Substring(array_CfgInfo[1].LastIndexOf("=") + 1);
+            Port = array_CfgInfo[2].Substring(array_CfgInfo[2].LastIndexOf("=") + 1);
+            User = array_CfgInfo[3].Substring(array_CfgInfo[3].LastIndexOf("=") + 1);
+            PassWd = array_CfgInfo[4].Substring(array_CfgInfo[4].LastIndexOf("=") + 1);
+            RootPath = array_CfgInfo[5].Substring(array_CfgInfo[5].LastIndexOf("=") + 1);
+            Local = array_CfgInfo[6].Substring(array_CfgInfo[6].LastIndexOf("=") + 1);
         }
     }
 }