EgwProxy.FTP
- aggiunta eliminazione elenco file in singolo step connessione
This commit is contained in:
@@ -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<FluentFTP.FtpListItem> resListFilt = new List<FluentFTP.FtpListItem>();
|
||||
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
|
||||
{
|
||||
|
||||
@@ -32,10 +32,10 @@ namespace EgwProxy.Ftp.Test
|
||||
createDir,
|
||||
delDir,
|
||||
delFile,
|
||||
delFileList,
|
||||
downloadDir,
|
||||
downloadFile,
|
||||
genRandomDir,
|
||||
getRemoteList,
|
||||
listContent,
|
||||
mirrorDirL2R,
|
||||
mirrorDirR2L,
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
{
|
||||
"id": "01",
|
||||
"description": "Generate Local Folder Data",
|
||||
"action": "getRemoteList",
|
||||
"action": "delFileList",
|
||||
"paramList": [
|
||||
"ftpdata/syncfolder/",
|
||||
".txt"
|
||||
"File_000.txt"
|
||||
]
|
||||
},
|
||||
//{
|
||||
|
||||
+33
-2
@@ -102,7 +102,7 @@ namespace EgwProxy.Ftp
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eliminazionedirectory remota
|
||||
/// Eliminazione file remoto
|
||||
/// </summary>
|
||||
/// <param name="remoteFile">Nome file remoto da eliminare</param>
|
||||
public bool DeleteFile(string remoteFile)
|
||||
@@ -124,6 +124,37 @@ namespace EgwProxy.Ftp
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eliminazione lista di files remoti
|
||||
/// </summary>
|
||||
/// <param name="remFileList">Lista file remoti da eliminare</param>
|
||||
public int DeleteFileList(List<string> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica esistenza directory su server FTP remoto
|
||||
/// </summary>
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
<HintPath>..\packages\EasyModbusTCP.5.6.0\lib\net40\EasyModbus.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EgwProxy.Ftp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EgwProxy.Ftp.3.6.2410.809\lib\EgwProxy.Ftp.dll</HintPath>
|
||||
<HintPath>..\packages\EgwProxy.Ftp.3.6.2410.815\lib\EgwProxy.Ftp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EgwProxy.Gomba, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EgwProxy.Gomba.3.6.2309.1416\lib\EgwProxy.Gomba.dll</HintPath>
|
||||
|
||||
@@ -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<FluentFTP.FtpListItem> resList = ftpClient.GetRemoteList(remoteVal, true);
|
||||
List<FluentFTP.FtpListItem> list2del = new List<FluentFTP.FtpListItem>();
|
||||
// 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:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<package id="Autoupdater.NET.Official" version="1.8.4" targetFramework="net462" />
|
||||
<package id="Costura.Fody" version="5.7.0" targetFramework="net462" developmentDependency="true" />
|
||||
<package id="EasyModbusTCP" version="5.6.0" targetFramework="net462" />
|
||||
<package id="EgwProxy.Ftp" version="3.6.2410.809" targetFramework="net462" />
|
||||
<package id="EgwProxy.Ftp" version="3.6.2410.815" targetFramework="net462" />
|
||||
<package id="EgwProxy.Gomba" version="3.6.2309.1416" targetFramework="net462" />
|
||||
<package id="EgwProxy.Icoel" version="3.6.2309.708" targetFramework="net462" />
|
||||
<package id="EgwProxy.MultiCncLib" version="3.6.2207.1211" targetFramework="net462" />
|
||||
|
||||
Reference in New Issue
Block a user