public void ProcessAllFtp() { _ConnectionString = Helper.LoadConfigKeys("ConnectionString");// +";Integrated Security=SSPI; trusted_connection=Yes;"; try{ _processes = GetDataFromDb(); } catch (Exception ex) { LogObj.WriteLog("Failed Accessing DB for windows user identity " + WindowsIdentity.GetCurrent() + " error:" + ex.Message, enMsgType.enMsgType_Error, _LogPrefix, _AppLogDirectory); } _AppLogDirectory = Helper.GetMyDir(_ConnectionString); foreach (Process p in _processes) { string res = "For Upload ProcessID " + p.ID + " HostIP " + p.HostIP + ": "; LogObj.WriteLog(res, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory); if (ValidInput(p)) { _results += res; p.LocalDir = _UploadFolder; //we change it to the user-selected folder ! FTPProcess ftp = new FTPProcess(p.RAM, p.HostIP, p.Port, p.Login, p.Password, p.RemoteDir, p.Pattern, _UploadFolder, p.PharmacyName, "not used here"); ftp.SetExcelTable(_tblExcel); IFtpType requiredTFtp = null; FtpFactory factory = new FtpFactory(); requiredTFtp = factory.CreateFtpFactory(p.FtpType, "upload", "", ""); res = ftp.ComputeFtp(requiredTFtp); _tblExcel = ftp.GetExcelTbl(); LogObj.WriteLog(res, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory); _results += res; } // LogObj.WriteLog(res, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory); _results += "\r\n"; } LogObj.WriteLog("Completed!", enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory); /* Create the Excel report */ try { if (_tblExcel == null) { throw new Exception("No Excel Report content was generated"); } CreateExcelFile.CreateExcelDocument(_tblExcel, _AppLogDirectory, _LogPrefix); } catch (Exception ex) { LogObj.WriteLog("Couldn't create Excel report. nException: " + ex.Message, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory); } }
private static void PassiveFtpModeExample() { var factory = new FtpFactory { Host = Host, User = User, Password = Pass, Type = FtpTypes.Ftp, Mode = FtpModes.Passive }; var service = new FtpService(factory); var items = service.GetListing(); Console.WriteLine($"Items found : {items.Count}"); }
//use to process through all download-processes in the db and then FTP the files. public void ProcessAllFtp(int hrsGoBack) { _ConnectionString = Helper.LoadConfigKeys("ConnectionString"); // + // ";Integrated Security=SSPI; trusted_connection=Yes;"; _SshHostKeyFingerPrint = Helper.LoadConfigKeys("SshHostKeyFingerPrint"); //not used anymore. _processes = GetDataFromDb(); _AppLogDirectory = Helper.GetMyDir(_ConnectionString); foreach (Process p in _processes) { string res = "For Download ProcessID " + p.ID + " HostIP " + p.HostIP + ": "; LogObj.WriteLog(res, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory); if (ValidInput(p)) { _results += res; FTPProcess ftp = new FTPProcess(p.RAM, p.HostIP, p.Port, p.Login, p.Password, p.RemoteDir, p.Pattern, p.LocalDir, p.PharmacyName, ""); ftp.NumDaysGoback(hrsGoBack); ftp.SetExcelTable(_tblExcel); //ftp.SetFingerPnt(_SshHostKeyFingerPrint); // we not passing the fingerprint, can ascertain it at time of fileDownload. IFtpType requiredTFtp = null; FtpFactory factory = new FtpFactory(); requiredTFtp = factory.CreateFtpFactory(p.FtpType, "download", p.RAM, p.Pattern); res = ftp.ComputeFtp(requiredTFtp); _tblExcel = ftp.GetExcelTbl(); LogObj.WriteLog(res, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory); _results += res; } } /* Create the Excel report */ LogObj.WriteLog("Completed!", enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory); try { CreateExcelFile.CreateExcelDocument(_tblExcel, _AppLogDirectory, _LogPrefix); } catch (Exception ex) { LogObj.WriteLog("Couldn't create Excel report. nException: " + ex.Message, enMsgType.enMsgType_Info, _LogPrefix, _AppLogDirectory); } }
private static void ActiveFtpModeExample() { var factory = new FtpFactory { Host = Host, User = User, Password = Pass, Type = FtpTypes.Ftp, Mode = FtpModes.Active, ActivePorts = new List <int> { 32490, 32491, 32492 } }; var service = new FtpService(factory); var items = service.GetListing(); Console.WriteLine($"Items found : {items.Count}"); }