EgwCoreLib.FTP
- Update conf FTP Server x avere mirror verbosi
This commit is contained in:
@@ -95,7 +95,7 @@ namespace EgwProxy.Ftp.Test
|
||||
if (item.paramList != null && item.paramList.Count > 0)
|
||||
{
|
||||
string dir2check = item.paramList[0];
|
||||
var dirCheckExists = ftpClient.dirExists(dir2check);
|
||||
var dirCheckExists = ftpClient.DirExists(dir2check);
|
||||
esitoStep = dirCheckExists ? $"Directory {dir2check} found!" : $"Directory {dir2check} NOT found!";
|
||||
}
|
||||
else
|
||||
@@ -108,7 +108,7 @@ namespace EgwProxy.Ftp.Test
|
||||
if (item.paramList != null && item.paramList.Count > 0)
|
||||
{
|
||||
string file2check = item.paramList[0];
|
||||
var dirCheckExists = ftpClient.fileExists(file2check);
|
||||
var dirCheckExists = ftpClient.FileExists(file2check);
|
||||
esitoStep = dirCheckExists ? $"File {file2check} found!" : $"File {file2check} NOT found!";
|
||||
}
|
||||
else
|
||||
@@ -121,14 +121,14 @@ namespace EgwProxy.Ftp.Test
|
||||
if (item.paramList != null && item.paramList.Count > 0)
|
||||
{
|
||||
string dir2check = item.paramList[0];
|
||||
var preTest = ftpClient.dirExists(dir2check);
|
||||
var preTest = ftpClient.DirExists(dir2check);
|
||||
if (preTest)
|
||||
{
|
||||
esitoStep = "Error: Folder already exists!";
|
||||
}
|
||||
else
|
||||
{
|
||||
var dirCreate = ftpClient.createDir(dir2check);
|
||||
var dirCreate = ftpClient.CreateDir(dir2check);
|
||||
esitoStep = dirCreate ? $"Directory {dir2check} created!" : $"Error: {dir2check} NOT created!";
|
||||
}
|
||||
|
||||
@@ -143,10 +143,10 @@ namespace EgwProxy.Ftp.Test
|
||||
if (item.paramList != null && item.paramList.Count > 0)
|
||||
{
|
||||
string dir2check = item.paramList[0];
|
||||
var preTest = ftpClient.dirExists(dir2check);
|
||||
var preTest = ftpClient.DirExists(dir2check);
|
||||
if (preTest)
|
||||
{
|
||||
var dirDelete = ftpClient.deleteDir(dir2check);
|
||||
var dirDelete = ftpClient.DeleteDir(dir2check);
|
||||
esitoStep = dirDelete ? $"Directory {dir2check} deleted!" : $"Error: {dir2check} NOT deleted!";
|
||||
}
|
||||
else
|
||||
@@ -165,10 +165,10 @@ namespace EgwProxy.Ftp.Test
|
||||
if (item.paramList != null && item.paramList.Count > 0)
|
||||
{
|
||||
string file2check = item.paramList[0];
|
||||
var preTest = ftpClient.fileExists(file2check);
|
||||
var preTest = ftpClient.FileExists(file2check);
|
||||
if (preTest)
|
||||
{
|
||||
var dirDelete = ftpClient.deleteFile(file2check);
|
||||
var dirDelete = ftpClient.DeleteFile(file2check);
|
||||
esitoStep = dirDelete ? $"File {file2check} deleted!" : $"Error: {file2check} NOT deleted!";
|
||||
}
|
||||
else
|
||||
@@ -188,10 +188,10 @@ namespace EgwProxy.Ftp.Test
|
||||
{
|
||||
string dir2check = item.paramList[0];
|
||||
string localDir = Path.Combine(BaseDirectory, item.paramList[1]);
|
||||
var preTest = ftpClient.dirExists(dir2check);
|
||||
var preTest = ftpClient.DirExists(dir2check);
|
||||
if (preTest)
|
||||
{
|
||||
var dirDelete = ftpClient.getDir(localDir, dir2check);
|
||||
var dirDelete = ftpClient.GetDir(localDir, dir2check);
|
||||
esitoStep = dirDelete ? $"Directory {dir2check} downloaded!" : $"Error: {dir2check} NOT downloaded!";
|
||||
}
|
||||
else
|
||||
@@ -211,10 +211,10 @@ namespace EgwProxy.Ftp.Test
|
||||
{
|
||||
string dir2check = item.paramList[0];
|
||||
string localDir = Path.Combine(BaseDirectory, item.paramList[1]);
|
||||
var preTest = ftpClient.dirExists(dir2check);
|
||||
var preTest = ftpClient.DirExists(dir2check);
|
||||
if (preTest)
|
||||
{
|
||||
var dirDelete = ftpClient.getDir(localDir, dir2check);
|
||||
var dirDelete = ftpClient.GetDir(localDir, dir2check);
|
||||
esitoStep = dirDelete ? $"Directory {dir2check} downloaded!" : $"Error: {dir2check} NOT downloaded!";
|
||||
}
|
||||
else
|
||||
@@ -234,7 +234,7 @@ namespace EgwProxy.Ftp.Test
|
||||
{
|
||||
string remoteDir = item.paramList[0];
|
||||
string localDir = Path.Combine(BaseDirectory, item.paramList[1]);
|
||||
var dirUploaded = ftpClient.sendDir(localDir, remoteDir);
|
||||
var dirUploaded = ftpClient.SendDir(localDir, remoteDir);
|
||||
esitoStep = dirUploaded ? $"Directory {remoteDir} uploaded!" : $"Error: {remoteDir} NOT uploaded!";
|
||||
}
|
||||
else
|
||||
@@ -248,7 +248,7 @@ namespace EgwProxy.Ftp.Test
|
||||
{
|
||||
string remotePath = item.paramList[0];
|
||||
string localPath = Path.Combine(BaseDirectory, item.paramList[1]);
|
||||
var fileUploaded = ftpClient.sendFile(localPath, remotePath);
|
||||
var fileUploaded = ftpClient.SendFile(localPath, remotePath);
|
||||
esitoStep = fileUploaded ? $"File {remotePath} uploaded!" : $"Error: {remotePath} NOT uploaded!";
|
||||
}
|
||||
else
|
||||
@@ -261,10 +261,10 @@ namespace EgwProxy.Ftp.Test
|
||||
if (item.paramList != null && item.paramList.Count > 0)
|
||||
{
|
||||
string remoteDir = item.paramList[0];
|
||||
var preTest = ftpClient.dirExists(remoteDir);
|
||||
var preTest = ftpClient.DirExists(remoteDir);
|
||||
if (preTest)
|
||||
{
|
||||
var listResult = ftpClient.listDir(remoteDir, false);
|
||||
var listResult = ftpClient.ListDir(remoteDir, false);
|
||||
Console.WriteLine($"Content of dir {remoteDir}:");
|
||||
foreach (var itemList in listResult)
|
||||
{
|
||||
@@ -335,13 +335,13 @@ namespace EgwProxy.Ftp.Test
|
||||
sw.Restart();
|
||||
string localDir = Path.Combine(BaseDirectory, item.paramList[0]);
|
||||
string remoteDir = item.paramList[1];
|
||||
var preTest = ftpClient.dirExists(remoteDir);
|
||||
var preTest = ftpClient.DirExists(remoteDir);
|
||||
if (!preTest)
|
||||
{
|
||||
ftpClient.createDir(remoteDir);
|
||||
ftpClient.CreateDir(remoteDir);
|
||||
}
|
||||
|
||||
var mirrorDone = ftpClient.sendDir(localDir, remoteDir, FluentFTP.FtpFolderSyncMode.Mirror);
|
||||
var mirrorDone = ftpClient.SendDir(localDir, remoteDir, FluentFTP.FtpFolderSyncMode.Mirror);
|
||||
esitoStep = mirrorDone ? $"Directory {localDir} mirrored L2R!" : $"Error: {remoteDir} NOT mirrored!";
|
||||
|
||||
}
|
||||
@@ -359,10 +359,10 @@ namespace EgwProxy.Ftp.Test
|
||||
sw.Restart();
|
||||
string remoteDir = item.paramList[0];
|
||||
string localDir = Path.Combine(BaseDirectory, item.paramList[1]);
|
||||
var preTest = ftpClient.dirExists(remoteDir);
|
||||
var preTest = ftpClient.DirExists(remoteDir);
|
||||
if (preTest)
|
||||
{
|
||||
var mirrorDone = ftpClient.getDir(localDir, remoteDir, FluentFTP.FtpFolderSyncMode.Mirror);
|
||||
var mirrorDone = ftpClient.GetDir(localDir, remoteDir, FluentFTP.FtpFolderSyncMode.Mirror);
|
||||
esitoStep = mirrorDone ? $"Directory {remoteDir} mirrored R2L!" : $"Error: {remoteDir} NOT mirrored!";
|
||||
}
|
||||
else
|
||||
@@ -414,7 +414,7 @@ namespace EgwProxy.Ftp.Test
|
||||
serverTest(ftpClient);
|
||||
|
||||
Console.WriteLine("--- Folder ---");
|
||||
var testExists = ftpClient.dirExists($"data/test_folder");
|
||||
var testExists = ftpClient.DirExists($"data/test_folder");
|
||||
if (testExists)
|
||||
{
|
||||
Console.WriteLine("Folder already exists!");
|
||||
@@ -422,12 +422,12 @@ namespace EgwProxy.Ftp.Test
|
||||
else
|
||||
{
|
||||
Console.WriteLine("--- Create folder ---");
|
||||
var testCreate = ftpClient.createDir($"data/test_folder");
|
||||
var testCreate = ftpClient.CreateDir($"data/test_folder");
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
Console.WriteLine("Contenuto folder remota: ");
|
||||
var folderContent = ftpClient.listDir("data/", true);
|
||||
var folderContent = ftpClient.ListDir("data/", true);
|
||||
foreach (var item in folderContent)
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
@@ -437,9 +437,9 @@ namespace EgwProxy.Ftp.Test
|
||||
Console.ReadKey();
|
||||
|
||||
Console.WriteLine("--- Upload file ---");
|
||||
ftpClient.sendFile("test/FileProva.txt", "data/test_folder/FileProva.txt");
|
||||
ftpClient.SendFile("test/FileProva.txt", "data/test_folder/FileProva.txt");
|
||||
Console.WriteLine("Contenuto folder remota: ");
|
||||
folderContent = ftpClient.listDir("data/", true);
|
||||
folderContent = ftpClient.ListDir("data/", true);
|
||||
foreach (var item in folderContent)
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
@@ -451,9 +451,9 @@ namespace EgwProxy.Ftp.Test
|
||||
|
||||
Console.WriteLine("--- Download File ---");
|
||||
|
||||
ftpClient.getFile("test/FileProva_02.txt", "data/test_folder/FileProva.txt");
|
||||
ftpClient.GetFile("test/FileProva_02.txt", "data/test_folder/FileProva.txt");
|
||||
Console.WriteLine("Contenuto folder remota: ");
|
||||
folderContent = ftpClient.listDir("data/", true);
|
||||
folderContent = ftpClient.ListDir("data/", true);
|
||||
foreach (var item in folderContent)
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
@@ -470,9 +470,9 @@ namespace EgwProxy.Ftp.Test
|
||||
private static void serverTest(Manager ftpClient)
|
||||
{
|
||||
Console.WriteLine(separator);
|
||||
var testServer = ftpClient.serverOk();
|
||||
var testServer = ftpClient.ServerOk();
|
||||
Console.WriteLine($"Test connessione: esito {testServer}");
|
||||
var srvType = ftpClient.serverType();
|
||||
var srvType = ftpClient.ServerType();
|
||||
Console.WriteLine($"Server: {srvType}");
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine();
|
||||
|
||||
@@ -37,8 +37,13 @@
|
||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=3.1.32.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.3.1.32\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.5.3.1\lib\net46\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
+184
-62
@@ -1,4 +1,5 @@
|
||||
using FluentFTP;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -7,9 +8,7 @@ using System.Net.Security;
|
||||
namespace EgwProxy.Ftp
|
||||
{
|
||||
/// <summary>
|
||||
/// Client per operazioni FTP, basato su FluentFTP:
|
||||
/// https://github.com/robinrodricks/FluentFTP
|
||||
/// https://github.com/robinrodricks/FluentFTP/wiki/Quick-Start-Example
|
||||
/// Client per operazioni FTP, basato su FluentFTP: https://github.com/robinrodricks/FluentFTP https://github.com/robinrodricks/FluentFTP/wiki/Quick-Start-Example
|
||||
/// </summary>
|
||||
public class Manager
|
||||
{
|
||||
@@ -54,11 +53,19 @@ namespace EgwProxy.Ftp
|
||||
/// Creazione directory remota
|
||||
/// </summary>
|
||||
/// <param name="remoteDir">Nome directory remota da creare (ad es: @"/public_html/videos")</param>
|
||||
public bool createDir(string remoteDir)
|
||||
public bool CreateDir(string remoteDir)
|
||||
{
|
||||
tryConnect();
|
||||
// upload della folder + files, cancellazione extra files = mirroring
|
||||
bool answ = client.CreateDirectory(remoteDir);
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
tryConnect();
|
||||
// upload della folder + files, cancellazione extra files = mirroring
|
||||
answ = client.CreateDirectory(remoteDir);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in CreateDir{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return answ;
|
||||
@@ -68,18 +75,20 @@ namespace EgwProxy.Ftp
|
||||
/// Eliminazionedirectory remota
|
||||
/// </summary>
|
||||
/// <param name="remoteDir">Nome directory remota da eliminare</param>
|
||||
public bool deleteDir(string remoteDir)
|
||||
public bool DeleteDir(string remoteDir)
|
||||
{
|
||||
tryConnect();
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
tryConnect();
|
||||
// Elimina folder
|
||||
client.DeleteDirectory(remoteDir);
|
||||
answ = true;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in DeleteDir{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return answ;
|
||||
@@ -89,18 +98,20 @@ namespace EgwProxy.Ftp
|
||||
/// Eliminazionedirectory remota
|
||||
/// </summary>
|
||||
/// <param name="remoteFile">Nome file remoto da eliminare</param>
|
||||
public bool deleteFile(string remoteFile)
|
||||
public bool DeleteFile(string remoteFile)
|
||||
{
|
||||
tryConnect();
|
||||
bool answ = false;
|
||||
tryConnect();
|
||||
try
|
||||
{
|
||||
// Elimina folder
|
||||
client.DeleteFile(remoteFile);
|
||||
answ = true;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in DeleteFile{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return answ;
|
||||
@@ -111,11 +122,19 @@ namespace EgwProxy.Ftp
|
||||
/// </summary>
|
||||
/// <param name="remotePath">Percorso remoto da testare (ad es "/htdocs/extras/")</param>
|
||||
/// <returns></returns>
|
||||
public bool dirExists(string remotePath)
|
||||
public bool DirExists(string remotePath)
|
||||
{
|
||||
tryConnect();
|
||||
bool answ = client.DirectoryExists(remotePath);
|
||||
// chiudo!
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
tryConnect();
|
||||
answ = client.DirectoryExists(remotePath);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in DirExists{Environment.NewLine}{exc}");
|
||||
}
|
||||
// c chiudo!
|
||||
client.Disconnect();
|
||||
return answ;
|
||||
}
|
||||
@@ -125,10 +144,18 @@ namespace EgwProxy.Ftp
|
||||
/// </summary>
|
||||
/// <param name="remotePath">Percorso remoto da testare (ad es "/htdocs/big2.txt")</param>
|
||||
/// <returns></returns>
|
||||
public bool fileExists(string remotePath)
|
||||
public bool FileExists(string remotePath)
|
||||
{
|
||||
tryConnect();
|
||||
bool answ = client.FileExists(remotePath);
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
tryConnect();
|
||||
answ = client.FileExists(remotePath);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in FileExists{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return answ;
|
||||
@@ -140,7 +167,7 @@ namespace EgwProxy.Ftp
|
||||
/// <param name="localDir">Path directory da inviare (ad es:@"C:\website\videos\")</param>
|
||||
/// <param name="remoteDir">Nome remoto file per caricamento (ad es: @"/public_html/videos")</param>
|
||||
/// <param name="syncMode">Modalità di sync (default = mirror)</param>
|
||||
public bool getDir(string localDir, string remoteDir, FtpFolderSyncMode syncMode = FtpFolderSyncMode.Mirror)
|
||||
public bool GetDir(string localDir, string remoteDir, FtpFolderSyncMode syncMode = FtpFolderSyncMode.Mirror)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
@@ -152,8 +179,10 @@ namespace EgwProxy.Ftp
|
||||
//answ = (result != null && result.Count > 0);
|
||||
answ = result != null && result.Where(x => !x.IsSuccess).Count() == 0;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in GetDir{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return answ;
|
||||
@@ -164,13 +193,20 @@ namespace EgwProxy.Ftp
|
||||
/// </summary>
|
||||
/// <param name="fileName">Path locale del file da inviare (ad es: @"C:\MyVideo.mp4")</param>
|
||||
/// <param name="remoteName">NOme remoto file per caricamento (ad es: "/htdocs/MyVideo.mp4")</param>
|
||||
public bool getFile(string fileName, string remoteName)
|
||||
public bool GetFile(string fileName, string remoteName)
|
||||
{
|
||||
bool answ = false;
|
||||
tryConnect();
|
||||
// effettuo caricamento puntuale
|
||||
var result = client.DownloadFile(fileName, remoteName);
|
||||
answ = result == FtpStatus.Success;
|
||||
try
|
||||
{
|
||||
tryConnect();
|
||||
// effettuo caricamento puntuale
|
||||
var result = client.DownloadFile(fileName, remoteName);
|
||||
answ = result == FtpStatus.Success;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in GetFile{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return answ;
|
||||
@@ -181,21 +217,29 @@ namespace EgwProxy.Ftp
|
||||
/// </summary>
|
||||
/// <param name="remoteDir">Nome directory remota da leggere (ad es: @"/public_html/videos")</param>
|
||||
/// <param name="recurse">Indica se fare search ricorsivo</param>
|
||||
public List<string> listDir(string remoteDir, bool recurse)
|
||||
public List<string> ListDir(string remoteDir, bool recurse)
|
||||
{
|
||||
tryConnect();
|
||||
// upload della folder + files, cancellazione extra files = mirroring
|
||||
FtpListItem[] dirContent;
|
||||
if (recurse)
|
||||
List<string> answ = new List<string>();
|
||||
try
|
||||
{
|
||||
dirContent = client.GetListing(remoteDir, FtpListOption.Recursive);
|
||||
tryConnect();
|
||||
// upload della folder + files, cancellazione extra files = mirroring
|
||||
FtpListItem[] dirContent;
|
||||
if (recurse)
|
||||
{
|
||||
dirContent = client.GetListing(remoteDir, FtpListOption.Recursive);
|
||||
}
|
||||
else
|
||||
{
|
||||
dirContent = client.GetListing(remoteDir);
|
||||
}
|
||||
answ = dirContent.Select(x => $"{x.Type} - {x.Name}").ToList();
|
||||
}
|
||||
else
|
||||
catch (Exception exc)
|
||||
{
|
||||
dirContent = client.GetListing(remoteDir);
|
||||
Log.Error($"Eccezione in ListDir{Environment.NewLine}{exc}");
|
||||
}
|
||||
client.Disconnect();
|
||||
var answ = dirContent.Select(x => $"{x.Type} - {x.Name}").ToList();
|
||||
// chiudo!
|
||||
return answ;
|
||||
}
|
||||
@@ -206,7 +250,54 @@ namespace EgwProxy.Ftp
|
||||
/// <param name="localDir">Path directory da inviare (ad es:@"C:\website\videos\")</param>
|
||||
/// <param name="remoteDir">Nome remoto file per caricamento (ad es: @"/public_html/videos")</param>
|
||||
/// <param name="syncMode">Modalità di sync (default = mirror)</param>
|
||||
public bool sendDir(string localDir, string remoteDir, FtpFolderSyncMode syncMode = FtpFolderSyncMode.Mirror)
|
||||
public List<FtpResult> MirrorLocalDir(string localDir, string remoteDir, FtpFolderSyncMode syncMode = FtpFolderSyncMode.Mirror)
|
||||
{
|
||||
List<FtpResult> jobResult = new List<FtpResult>();
|
||||
try
|
||||
{
|
||||
tryConnect();
|
||||
jobResult = client.UploadDirectory(localDir, remoteDir, syncMode);
|
||||
//answ = (result != null && result.Count > 0);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in MirrorLocalDir{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return jobResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scaricamento intera directory, modalità MIRROR, con restituzione elenco esiti
|
||||
/// </summary>
|
||||
/// <param name="localDir">Path directory da inviare (ad es:@"C:\website\videos\")</param>
|
||||
/// <param name="remoteDir">Nome remoto file per caricamento (ad es: @"/public_html/videos")</param>
|
||||
/// <param name="syncMode">Modalità di sync (default = mirror)</param>
|
||||
public List<FtpResult> MirrorRemoteDir(string localDir, string remoteDir, FtpFolderSyncMode syncMode = FtpFolderSyncMode.Mirror)
|
||||
{
|
||||
List<FtpResult> jobResult = new List<FtpResult>();
|
||||
try
|
||||
{
|
||||
tryConnect();
|
||||
jobResult = client.DownloadDirectory(localDir, remoteDir, syncMode);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in mirrorRemoteDir{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return jobResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Caricamento intera directory, modalità MIRROR
|
||||
/// </summary>
|
||||
/// <param name="localDir">Path directory da inviare (ad es:@"C:\website\videos\")</param>
|
||||
/// <param name="remoteDir">Nome remoto file per caricamento (ad es: @"/public_html/videos")</param>
|
||||
/// <param name="syncMode">Modalità di sync (default = mirror)</param>
|
||||
public bool SendDir(string localDir, string remoteDir, FtpFolderSyncMode syncMode = FtpFolderSyncMode.Mirror)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
@@ -218,8 +309,10 @@ namespace EgwProxy.Ftp
|
||||
//answ = (result != null && result.Count > 0);
|
||||
answ = result != null && result.Where(x => !x.IsSuccess).Count() == 0;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in SendDir{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return answ;
|
||||
@@ -230,17 +323,25 @@ namespace EgwProxy.Ftp
|
||||
/// </summary>
|
||||
/// <param name="fileName">Path locale del file da inviare (ad es: @"C:\MyVideo.mp4")</param>
|
||||
/// <param name="remoteName">NOme remoto file per caricamento (ad es: "/htdocs/MyVideo.mp4")</param>
|
||||
public bool sendFile(string fileName, string remoteName)
|
||||
public bool SendFile(string fileName, string remoteName)
|
||||
{
|
||||
bool answ = false;
|
||||
tryConnect();
|
||||
// effettuo caricamento puntuale
|
||||
var result = client.UploadFile(fileName, remoteName);
|
||||
answ = result == FtpStatus.Success;
|
||||
// se insuccesso --> controllo se ci sia file...
|
||||
if (!answ)
|
||||
try
|
||||
{
|
||||
answ = fileExists(remoteName);
|
||||
tryConnect();
|
||||
tryConnect();
|
||||
// effettuo caricamento puntuale
|
||||
var result = client.UploadFile(fileName, remoteName);
|
||||
answ = result == FtpStatus.Success;
|
||||
// se insuccesso --> controllo se ci sia file...
|
||||
if (!answ)
|
||||
{
|
||||
answ = FileExists(remoteName);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in SendFile{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
@@ -251,10 +352,18 @@ namespace EgwProxy.Ftp
|
||||
/// Verifica connessione con server FTP remoto
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool serverOk()
|
||||
public bool ServerOk()
|
||||
{
|
||||
tryConnect();
|
||||
bool answ = client.IsConnected;
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
tryConnect();
|
||||
answ = client.IsConnected;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in ServerOk{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return answ;
|
||||
@@ -264,13 +373,22 @@ namespace EgwProxy.Ftp
|
||||
/// Restituisce tipo server remoto
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string serverType()
|
||||
public string ServerType()
|
||||
{
|
||||
tryConnect();
|
||||
FtpServer srvType = client.ServerType;
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
tryConnect();
|
||||
FtpServer srvType = client.ServerType;
|
||||
answ = $"{srvType}";
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in ServerType{Environment.NewLine}{exc}");
|
||||
}
|
||||
// chiudo!
|
||||
client.Disconnect();
|
||||
return $"{srvType}";
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
@@ -284,14 +402,18 @@ namespace EgwProxy.Ftp
|
||||
#region Protected Properties
|
||||
|
||||
protected string _passwd { get; set; } = "";
|
||||
|
||||
protected string _rawCert { get; set; } = "";
|
||||
protected string _server { get; set; } = "";
|
||||
|
||||
protected string _userName { get; set; } = "";
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private FtpClient client { get; set; }
|
||||
@@ -308,9 +430,9 @@ namespace EgwProxy.Ftp
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{e.PolicyErrors}");
|
||||
Console.WriteLine($"Cert:{Environment.NewLine}{e.Certificate}");
|
||||
Console.WriteLine($"RawString:{Environment.NewLine}{e.Certificate.GetRawCertDataString()}");
|
||||
Log.Error($"{e.PolicyErrors}");
|
||||
Log.Error($"Cert:{Environment.NewLine}{e.Certificate}");
|
||||
Log.Error($"RawString:{Environment.NewLine}{e.Certificate.GetRawCertDataString()}");
|
||||
throw new Exception($"{e.PolicyErrors}{Environment.NewLine}{e.Certificate.GetRawCertDataString()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
<packages>
|
||||
<package id="FluentFTP" version="51.1.0" targetFramework="net462" />
|
||||
<package id="Microsoft.Extensions.Logging.Abstractions" version="3.1.32" targetFramework="net462" />
|
||||
<package id="NLog" version="5.3.1" targetFramework="net462" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net462" />
|
||||
</packages>
|
||||
@@ -8,7 +8,7 @@
|
||||
"ConnPasswd": "we4reFromB3rghem!",
|
||||
"RawCert": "",
|
||||
"SkipCert": true,
|
||||
"ReExecVeto": 120,
|
||||
"ReExecVeto": 90,
|
||||
"Note": "Sync periodico completo",
|
||||
"StepsList": [
|
||||
{
|
||||
|
||||
@@ -168,10 +168,10 @@ namespace IOB_WIN_NEXT.IobNet
|
||||
public override void processCustomTaskLF()
|
||||
{
|
||||
lgInfo($"Richiesto processCustomTaskLF");
|
||||
|
||||
// verifico di avere compiti da svolgere...
|
||||
if (currFtpTaskList != null && currFtpTaskList.ListTask != null && currFtpTaskList.ListTask.Count > 0)
|
||||
{
|
||||
string sVal = "";
|
||||
foreach (var srvFtp in currFtpTaskList.ListTask)
|
||||
{
|
||||
// verifico eventuale veto all'esecuzione...
|
||||
@@ -192,6 +192,16 @@ namespace IOB_WIN_NEXT.IobNet
|
||||
{
|
||||
bool fatto = doStep(step);
|
||||
stepDone += fatto ? 1 : 0;
|
||||
// modificare: ricevere elenco di TUTTI i file con esito
|
||||
|
||||
#if false
|
||||
// per i file SCARICATI registrare in FLog...
|
||||
string key = "FtpSync";
|
||||
string value = "SRC --> DEST | MB | ms";
|
||||
sVal = $"{key} | {value}";
|
||||
accodaFLog(sVal, qEncodeFLog(key, value));
|
||||
#endif
|
||||
|
||||
}
|
||||
lgInfo($"Completata esecuzione steps FTP | {srvFtp.ActionId} | {stepDone}/{srvFtp.StepsList.Count} Done/Req");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user