#if false using EgwProxy.Ftp; #endif using EgwProxy.MultiCncLib.App.Native; using IOB_UT_NEXT; using IOB_WIN_FORM; using MapoSDK; using MathNet.Numerics.Statistics; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NLog; using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml.Serialization; using static IOB_UT_NEXT.BaseAlarmConf; using static IOB_UT_NEXT.CustomObj; using static IOB_UT_NEXT.DataModel.Fimat; using static MapoSDK.WharehouseData; namespace IOB_WIN_NEXT.Iob { public class GenericNext : IOB_WIN_FORM.Iob.Generic { public GenericNext(AdapterFormNext caller, IobConfiguration IOBConf): base((IOB_WIN_FORM.AdapterForm)caller, IOBConf) { } #if false /// /// Effettua upload verso server FTP della macchina dei files nella folder indicata /// /// /// protected override bool iobSendFTP(string folderDir) { bool answ = false; //leggo CONF string ftpServ = getOptPar("FTP_SERVER"); string ftpUser = getOptPar("FTP_USER"); string ftpPass = getOptPar("FTP_PWD"); string ftpCert = getOptPar("FTP_CERT"); string doSkip = getOptPar("FTP_SKIP"); string remDir = getOptPar("FTP_REM_DIR"); string locDir = getOptPar("FTP_LOC_DIR"); // procedo SE TROVO conf... if (string.IsNullOrEmpty($"{ftpServ}{ftpUser}{ftpPass}")) { lgError($"Impossibile eseguire iobSendFTP x mancanza parametri | ftpServ: {ftpServ} | ftpUser: {ftpUser} | ftpPass: {ftpPass}"); } else { bool ftpSkip = false; bool.TryParse(doSkip, out ftpSkip); var ftpClient = new Manager(ftpServ, ftpUser, ftpPass, ftpCert, ftpSkip); var testServer = ftpClient.ServerOk(); if (testServer) { lgInfo($"FTP: server found at {ftpServ}"); var srvType = ftpClient.ServerType(); lgInfo($"FTP Server type: {srvType}"); var preTest = ftpClient.DirExists(remDir); if (!preTest) { var dirCreate = ftpClient.CreateDir(remDir); lgInfo($"FTP: created remote dir {remDir}"); } // test directory... string basePath = Application.StartupPath; string localPath = Path.Combine(basePath, locDir); lgInfo($"basePath: {basePath} | localPath: {localPath}"); var fileList = Directory.GetFiles(localPath, "*.csv"); int numfile = 0; foreach (var file in fileList) { string fName = file.Split('\\').Last(); string remName = $"{remDir}\\{fName}"; ftpClient.SendFile(file, remName); numfile++; } var dirUploaded = (numfile == fileList.Count()); if (dirUploaded) { lgInfo($"FTP: uploaded dir content {locDir} --> {remDir}"); } // se ok --> sposto invio DateTime adesso = DateTime.Now; string archBasePath = Path.Combine(basePath, "DATA", "HIST", $"{adesso:yyyy}"); baseUtils.checkDir(archBasePath); string archPath = Path.Combine(archBasePath, $"{adesso:MMddHHmmss}"); baseUtils.checkDir(archPath); lgInfo($"Richiesta Dir Move | {localPath} | {archPath}"); foreach (var item in fileList) { string fName = item.Split('\\').Last(); string destName = $"{archPath}\\{fName}"; File.Move(item, destName); } //Directory.Move(localPath, archBasePath); lgInfo($"FTP: Archived dir content {localPath} --> {archPath}"); } } return answ; } #endif } }