using System; using Fab2ApprovalSystem.Models; namespace Fab2ApprovalSystem.Misc; internal class FTPWrapper { private readonly string _OutputFile; private readonly string _DestinationFileName; private readonly AppSettings _AppSettings; public FTPWrapper(AppSettings appSettings, string outputFile, string destinationFileName) { _OutputFile = outputFile; _AppSettings = appSettings; _DestinationFileName = destinationFileName; } public void FTPToSPN() { FTP ftpLib = new(); // Connect to the FTP server try { ftpLib.Connect(_AppSettings.FTPServer, _AppSettings.FTPUser, _AppSettings.FTPPassword); } catch (Exception ec) { Functions.WriteEvent(_AppSettings, "Listener - ProcessFile(): FTP Connection Error " + _OutputFile + " - " + ec.Source + ": " + ec.Message, System.Diagnostics.EventLogEntryType.Error); } // Upload the file try { int pct = 0; ftpLib.OpenUpload(_OutputFile, _DestinationFileName); while (ftpLib.DoUpload() > 0) pct = (int)((ftpLib.BytesTotal * 100) / ftpLib.FileSize); Functions.WriteEvent(_AppSettings, _OutputFile + " was sucessfully FTPed to SPN.", System.Diagnostics.EventLogEntryType.Information); } catch (Exception eu) { Functions.WriteEvent(_AppSettings, "MRB - FTPToSPN(): FTP Upload Error " + _OutputFile + " - " + eu.Source + ": " + eu.Message, System.Diagnostics.EventLogEntryType.Error); throw new Exception(eu.Source + ": " + eu.Message); } } }