diff --git a/EgwProxy.Ftp.Test/Program.cs b/EgwProxy.Ftp.Test/Program.cs index 13207ec9..440e5265 100644 --- a/EgwProxy.Ftp.Test/Program.cs +++ b/EgwProxy.Ftp.Test/Program.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Configuration; using System.Diagnostics; using System.IO; +using System.Linq; using System.Text; using static System.Net.Mime.MediaTypeNames; @@ -375,7 +376,7 @@ namespace EgwProxy.Ftp.Test esitoStep = $"Completato mirror R2L: {sw.ElapsedMilliseconds:N1} ms"; break; - case stepType.getRemoteList: + case stepType.delFileList: if (item.paramList != null && item.paramList.Count > 1) { sw.Restart(); @@ -386,15 +387,18 @@ namespace EgwProxy.Ftp.Test List resListFilt = new List(); foreach (var flItem in resList) { - if(flItem.Type == FluentFTP.FtpObjectType.File && flItem.Name.Contains(fileSearch)) + if(flItem.Type == FluentFTP.FtpObjectType.File && flItem.Name.EndsWith(fileSearch)) { resListFilt.Add(flItem); } } - + // elimino quelli trovati if (resListFilt.Count>0) { - esitoStep = $"Trovati {resListFilt.Count} file"; + var fList = resListFilt.Select(x => x.FullName).ToList(); + var numDel = ftpClient.DeleteFileList(fList); + // indico esito eliminazione + esitoStep = $"Eliminati {numDel}/{resListFilt.Count} file"; } else { diff --git a/EgwProxy.Ftp.Test/TestSetup.cs b/EgwProxy.Ftp.Test/TestSetup.cs index d3f7e480..fc7f167d 100644 --- a/EgwProxy.Ftp.Test/TestSetup.cs +++ b/EgwProxy.Ftp.Test/TestSetup.cs @@ -32,10 +32,10 @@ namespace EgwProxy.Ftp.Test createDir, delDir, delFile, + delFileList, downloadDir, downloadFile, genRandomDir, - getRemoteList, listContent, mirrorDirL2R, mirrorDirR2L, diff --git a/EgwProxy.Ftp.Test/conf/testSetup.json b/EgwProxy.Ftp.Test/conf/testSetup.json index d5c003ad..b70e0936 100644 --- a/EgwProxy.Ftp.Test/conf/testSetup.json +++ b/EgwProxy.Ftp.Test/conf/testSetup.json @@ -8,10 +8,10 @@ { "id": "01", "description": "Generate Local Folder Data", - "action": "getRemoteList", + "action": "delFileList", "paramList": [ "ftpdata/syncfolder/", - ".txt" + "File_000.txt" ] }, //{ diff --git a/EgwProxy.Ftp/Manager.cs b/EgwProxy.Ftp/Manager.cs index 8141752a..1f208036 100644 --- a/EgwProxy.Ftp/Manager.cs +++ b/EgwProxy.Ftp/Manager.cs @@ -102,7 +102,7 @@ namespace EgwProxy.Ftp } /// - /// Eliminazionedirectory remota + /// Eliminazione file remoto /// /// Nome file remoto da eliminare public bool DeleteFile(string remoteFile) @@ -124,6 +124,37 @@ namespace EgwProxy.Ftp return answ; } + /// + /// Eliminazione lista di files remoti + /// + /// Lista file remoti da eliminare + public int DeleteFileList(List remFileList) + { + int numDone = 0; + tryConnect(); + try + { + foreach (var remoteFile in remFileList) + { + // Elimina folder + client.DeleteFile(remoteFile); + // verifico se sia presente... + bool fExist = client.FileExists(remoteFile); + if (!fExist) + { + numDone++; + } + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in DeleteFileList{Environment.NewLine}{exc}"); + } + // chiudo! + client.Disconnect(); + return numDone; + } + /// /// Verifica esistenza directory su server FTP remoto /// @@ -455,7 +486,7 @@ namespace EgwProxy.Ftp #region Private Properties - private FtpClient client { get; set; } + private FtpClient client { get; set; } = new FtpClient(); #endregion Private Properties diff --git a/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj b/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj index 005db73c..6805a039 100644 --- a/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj +++ b/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj @@ -111,7 +111,7 @@ ..\packages\EasyModbusTCP.5.6.0\lib\net40\EasyModbus.dll - ..\packages\EgwProxy.Ftp.3.6.2410.809\lib\EgwProxy.Ftp.dll + ..\packages\EgwProxy.Ftp.3.6.2410.815\lib\EgwProxy.Ftp.dll ..\packages\EgwProxy.Gomba.3.6.2309.1416\lib\EgwProxy.Gomba.dll diff --git a/IOB-WIN-NEXT/IobNet/Ftp.cs b/IOB-WIN-NEXT/IobNet/Ftp.cs index 2e747c15..1afd1416 100644 --- a/IOB-WIN-NEXT/IobNet/Ftp.cs +++ b/IOB-WIN-NEXT/IobNet/Ftp.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.IO.Packaging; using System.Linq; using System.Net.NetworkInformation; using System.Text; @@ -190,7 +191,7 @@ namespace IOB_WIN_NEXT.IobNet //string remFile = $"{RemoteBaseDir}/{odlFolder}/{fName}"; // creo file locale File.WriteAllText(locFile, item.Value); - // creo file temp x invio + // invio file x ODL attivo currActParam.Add("LocalFile", locFile); currActParam.Add("RemoteFile", remFile); currAct = new ActionConfig() @@ -214,7 +215,25 @@ namespace IOB_WIN_NEXT.IobNet break; case taskType.endProd: - // cerco tutti i file dell'odl arttivo e li elimino + currActParam.Add("RemoteDir", RemoteBaseDir); + currActParam.Add("FileName2Del", fNameOdl); + currAct = new ActionConfig() + { + Id = "01", + Description = "Clean Curr ODL Files", + Action = ActType.RemoveFileByName, + ParamList = currActParam + }; + // eseguo step... + taskOk = doStep(currAct); + if (taskOk) + { + taskVal = $"Cleaned CurrOdlFile: {item.Key} --> {item.Value} | remDir: {RemoteBaseDir} | fName: {fNameOdl}"; + } + else + { + lgError($"Error in CurrOdlFile | remDir: {RemoteBaseDir} | fName: {fNameOdl}"); + } break; @@ -666,6 +685,51 @@ namespace IOB_WIN_NEXT.IobNet break; case ActType.PingServer: + break; + + case ActType.RemoveFileByName: + string fName2Del = ""; + int numRem = 0; + if (step.ParamList != null && step.ParamList.Count > 1) + { + sw.Restart(); + remoteVal = step.ParamList["RemoteDir"] ?? ""; + fName2Del = step.ParamList["FileName2Del"] ?? ""; + //verifico dir remota + fatto = ftpClient.DirExists(remoteVal); + if (fatto) + { + // recupero elenco di TUTTI i file presenti + List resList = ftpClient.GetRemoteList(remoteVal, true); + List list2del = new List(); + // cerco tutti i file che indicano ODL attivo e li elimino + foreach (var flItem in resList) + { + if (flItem.Type == FluentFTP.FtpObjectType.File && flItem.Name.EndsWith(fName2Del)) + { + list2del.Add(flItem); + } + } + // ciclo sui file da eliminare... + foreach (var file2del in list2del) + { + bool delOk= ftpClient.DeleteFile(file2del.FullName); + numRem += delOk ? 1 : 0; + } + } + } + else + { + lgError("Error: missing parameters!"); + } + sw.Stop(); + if (fatto) + { + lgInfo($"RemoveFileByName | path: {remoteVal} | name: {fName2Del} | # del: {numRem} | {sw.ElapsedMilliseconds:N1} ms"); + } + + + break; case ActType.UploadDir: diff --git a/IOB-WIN-NEXT/packages.config b/IOB-WIN-NEXT/packages.config index 1813249c..552c5993 100644 --- a/IOB-WIN-NEXT/packages.config +++ b/IOB-WIN-NEXT/packages.config @@ -3,7 +3,7 @@ - +