/// <summary> /// Log to a text file /// </summary> private static void LogToFile() { FtpTrace.AddListener(new TextWriterTraceListener("log_file.txt")); // now use System.Net.FtpCLient as usual and the server transactions // will be written to the specified log file. }
public FTPClientForm(FTPAccount account) { InitializeComponent(); Icon = ShareXResources.Icon; lblStatus.Text = string.Empty; lvFTPList.SubItemEndEditing += lvFTPList_SubItemEndEditing; FtpTrace.AddListener(new TextBoxTraceListener(txtDebug)); Account = account; Client = new FTP(account); pgAccount.SelectedObject = Client.Account; Text = Resources.FTPClientForm_FTPClientForm_ShareX_FTP_client + " - " + account.Name; lblConnecting.Text = string.Format(Resources.FTPClientForm_FTPClientForm_Connecting_to__0_, account.FTPAddress); TaskEx.Run(() => { Client.Connect(); }, () => { pConnecting.Visible = false; Refresh(); RefreshDirectory(); }); }
public static void Initialize() { FtpTrace.AddListener(new NLog.NLogTraceListener()); Logger.Info("Engines initializing"); ConnectionStringSettings connectionStringPrimary = ConfigurationManager.ConnectionStrings["tasConnectionString"]; ConnectionStringSettings connectionStringSecondary = ConfigurationManager.ConnectionStrings["tasConnectionStringSecondary"]; Database = DatabaseProviderLoader.LoadDatabaseProvider(); Logger.Debug("Connecting to database"); Database.Open(connectionStringPrimary?.ConnectionString, connectionStringSecondary?.ConnectionString); _servers = Database.LoadServers <CasparServer>(); _servers.ForEach(s => { s.ChannelsSer.ForEach(c => c.Owner = s); s.RecordersSer.ForEach(r => r.SetOwner(s)); }); var authenticationService = new AuthenticationService(Database.Load <User>(), Database.Load <Group>()); Engines = Database.LoadEngines <Engine>(ulong.Parse(ConfigurationManager.AppSettings["Instance"])); foreach (var e in Engines) { e.Initialize(_servers, authenticationService); } Logger.Debug("Engines initialized"); }
public void InitializeEngines() { FtpTrace.AddListener(new NLog.NLogTraceListener()); Logger.Info("Engines initializing"); Servers = DatabaseProvider.Database.LoadServers <CasparServer>(); foreach (var s in Servers) { s.ChannelsSer.ForEach(c => c.Owner = s); s.RecordersSer.ForEach(r => r.SetOwner(s)); } Engines = DatabaseProvider.Database.LoadEngines <Engine>(ulong.Parse(ConfigurationManager.AppSettings["Instance"])); LoadArchiveDirectories(); foreach (var e in Engines) { e.Initialize(Servers); } Logger.Debug("Engines initialized"); Task.Run(() => { foreach (var e in Engines) { ((MediaManager)e.MediaManager).Initialize( ArchiveDirectories.FirstOrDefault(a => a.IdArchive == e.IdArchive)); } Logger.Debug("All media managers initialized"); }); }
internal static void Execute(Options options) { if (options == null) { throw new ArgumentNullException("options"); } if (options.Verbose) { FtpTrace.AddListener(new System.Diagnostics.ConsoleTraceListener()); } using (FtpClient client = new FtpClient()) { client.Host = options.Host; client.Port = options.Port; if (options.User != null) { client.Credentials = new NetworkCredential(options.User, options.Password); } client.DataConnectionType = FtpDataConnectionType.PASV; //TODO: 参数化 client.EncryptionMode = FtpEncryptionMode.Explicit; client.ValidateCertificate += new FtpSslValidation(OnValidateCertificate); client.DataConnectionConnectTimeout = options.Timeout * 1000; client.Connect(); var commands = CreateCommands(); foreach (var cmd in commands) { cmd.Execute(options, client); } } }
/// <summary> /// Log to a console window /// </summary> private static void LogToConsole() { FtpTrace.AddListener(new ConsoleTraceListener()); // now use System.Net.FtpCLient as usual and the server transactions // will be written to the Console window. }
private void App_Startup(object sender, StartupEventArgs e) { FtpTrace.AddListener(new ConsoleTraceListener()); FtpTrace.LogUserName = false; // hide FTP user names FtpTrace.LogPassword = false; // hide FTP passwords FtpTrace.LogIP = false; // hide FTP server IP addresses }
private void frmFtpClientTest_Load(object sender, EventArgs e) { Setup.SetCustomExceptionHandler(); logger = new LoggerTraceListener(); logger.OnTraceEvent += Logger_OnTraceEvent; FtpTrace.AddListener(logger); FtpTrace.LogFunctions = false; }
private async void button1_Click(object sender, EventArgs e) { FtpTrace.AddListener(log); ftp = new FtpClient("ftp.darkmaster.no", 21, "darkmaster.no", "styx2007"); await ftp.ConnectAsync(); explorer1.ftpClient = ftp; explorer1.IsPcExplorer = false; await explorer1.RefreshCurrentFtpFolder(true); }
public static bool Connect(bool OfflineMode = false) { bool result = false; try { FTPFile = IBMiUtils.GetLocalFile("QTEMP", "FTPLOG", DateTime.Now.ToString("MMddTHHmm"), "txt"); FtpTrace.AddListener(new TextWriterTraceListener(FTPFile)); FtpTrace.LogUserName = false; // hide FTP user names FtpTrace.LogPassword = false; // hide FTP passwords FtpTrace.LogIP = false; // hide FTP server IP addresses string password = Password.Decode(CurrentSystem.GetValue("password")); Client = new FtpClient(CurrentSystem.GetValue("system"), CurrentSystem.GetValue("username"), password); if (OfflineMode == false) { Client.UploadDataType = FtpDataType.ASCII; Client.DownloadDataType = FtpDataType.ASCII; //FTPES is configurable if (IBMi.CurrentSystem.GetValue("useFTPES") == "true") { Client.EncryptionMode = FtpEncryptionMode.Explicit; } //Client.DataConnectionType = FtpDataConnectionType.AutoPassive; //THIS IS THE DEFAULT VALUE Client.DataConnectionType = GetFtpDataConnectionType(CurrentSystem.GetValue("transferMode")); Client.SocketKeepAlive = true; Client.ConnectTimeout = 5000; Client.Connect(); //Change the user library list on connection RemoteCommand($"CHGLIBL LIBL({ CurrentSystem.GetValue("datalibl").Replace(',', ' ')}) CURLIB({ CurrentSystem.GetValue("curlib") })"); System.Timers.Timer timer = new System.Timers.Timer(); timer.Interval = 60000; timer.Elapsed += new ElapsedEventHandler(KeepAliveFunc); timer.Start(); } result = true; } catch (Exception e) { MessageBox.Show("Unable to connect to " + CurrentSystem.GetValue("system") + " - " + e.Message, "Cannot Connect", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(result); }
//--------------------Loading/Closing Events-------------------- private void MainForm_Load(object sender, EventArgs e) { // custom debug console for FTP-connections FtpTrace.AddListener(new TextBoxListener(EasyConsole)); FtpTrace.LogUserName = false; // hide FTP user names FtpTrace.LogPassword = false; // hide FTP passwords // Create Models modify = new Modify(this); transfer = new Transfer(this); // populates the local TreeView PopulateTreeViewLocal(); }
/// <summary> /// Enables or disables FTP logging /// </summary> /// <param name="isSet">Enable or disable logging</param> public void SetFtpLogging(bool isSet) { try { FtpTrace.RemoveListener(FtpTraceListener); } catch { // ignored } if (isSet) { FtpTrace.AddListener(FtpTraceListener); FtpTrace.FlushOnWrite = true; } }
public FTPClientForm(FTPAccount account) { InitializeComponent(); Icon = ShareXResources.Icon; lblStatus.Text = ""; lvFTPList.SubItemEndEditing += lvFTPList_SubItemEndEditing; FtpTrace.AddListener(new TextBoxTraceListener(txtDebug)); Account = account; Client = new FTP(account); pgAccount.SelectedObject = Client.Account; Text = Resources.FTPClientForm_FTPClientForm_ShareX_FTP_client + " - " + account.Name; lblConnecting.Text = string.Format(Resources.FTPClientForm_FTPClientForm_Connecting_to__0_, account.FTPAddress); }
private void chkFTPTrace_CheckedChanged(object sender, EventArgs e) { if (chkFTPTrace.Checked) { if (_EventListBoxTrace == null) { _EventListBoxTrace = new EventListTraceLog(this); } FtpTrace.AddListener(_EventListBoxTrace); } else { if (_EventListBoxTrace != null) { FtpTrace.RemoveListener(_EventListBoxTrace); } } }
private void frmFtpConnectUploadDownloadTest_Load(object sender, EventArgs e) { myLog = new LoggerTraceListener(); explorer1.queueList = queueList1; explorer1.IsPcExplorer = false; explorer1.OtherExplorer = explorer2; explorer2.queueList = queueList1; explorer2.IsPcExplorer = true; explorer2.RefreshCurrentPcFolder(); explorer2.OtherExplorer = explorer1; queueList1._explorer1 = explorer1; queueList1._explorer2 = explorer2; //listBox1.SelectionMode = SelectionMode.None; FtpTrace.LogFunctions = false; FtpTrace.AddListener(myLog); myLog.OnTraceEvent += MyLog_OnTraceEvent; }
private static void Main(Arguments args) { if (args.BackgroundConnectionCount < 0) { throw new ArgumentValidationException("Parallel count cannot be negative."); } if (args.BackgroundConnectionCount < 1) { throw new NotSupportedException("Current implementaton requires at least one background connection (this might be improved in the future)."); } if (args.Verbose) { FtpTrace.AddListener(new ConsoleTraceListener()); } var ftpUrl = new Uri(args.FtpUrl); var password = Environment.GetEnvironmentVariable(args.FtpPasswordVariableName, EnvironmentVariableTarget.Process); if (string.IsNullOrEmpty(password)) { throw new ArgumentValidationException($"Password env variable '{args.FtpPasswordVariableName}' is not set for the current process (user/machine vars are ignored)."); } FluentConsole.White.Line(ftpUrl); var started = DateTime.Now; var basePath = ftpUrl.LocalPath; var credentials = new NetworkCredential(args.FtpUserName, password); var sourceInfo = Directory.Exists(args.SourcePath) ? (FileSystemInfo) new DirectoryInfo(args.SourcePath) : new FileInfo(args.SourcePath); using (var mainClient = CreateFtpClient(ftpUrl, credentials, args.FtpUseActive, retry: args.InterimFtpRetryLogin)) using (var backgroundPool = new FtpClientPool(() => CreateFtpClient(ftpUrl, credentials, args.FtpUseActive, retry: true), args.BackgroundConnectionCount)) using (var process = new Process(mainClient, backgroundPool, args.Excludes.AsReadOnlyList())) { process.SynchronizeTopLevel(sourceInfo, basePath); } FluentConsole.NewLine().Green.Line(@"Finished in {0:dd\.hh\:mm\:ss}.", DateTime.Now - started); }
internal ResumeCapability Connect(FtpConnection connection, bool addTraceListener = true, EventHandler <FtpGetListingEventArgs> onGetListingDataReceived = null) { _ftpClient = new FtpClient { EnableThreadSafeDataConnections = false, DataConnectionType = connection.UsePassiveMode ? FtpDataConnectionType.PASV : FtpDataConnectionType.PORT, Host = connection.Address, Port = connection.Port }; if (addTraceListener) { FtpTrace.AddListener(TraceListener); } Connection = connection; _ftpClient.BeforeAuthentication += OnBeforeAuthentication; _ftpClient.Connected += OnConnected; if (onGetListingDataReceived != null) { _ftpClient.GetListingDataReceived += onGetListingDataReceived; } _ftpClient.Connect(); var resume = ResumeCapability.None; var r = FtpClient.Execute("APPE"); if (!r.Message.Contains("command not recognized")) { resume |= ResumeCapability.Append; } r = FtpClient.Execute("REST"); if (!r.Message.Contains("command not recognized")) { resume |= ResumeCapability.Restart; } return(resume); }
public static bool AddFileListner(string file, SourceLevels level = FtpConstants.DefaultLevel) { if (string.IsNullOrWhiteSpace(file)) { return(false); } try { using (var listner = new TextWriterTraceListener(file)) { listner.Filter = new EventTypeFilter(level); FtpTrace.AddListener(listner); FtpTrace.LogUserName = true; FtpTrace.LogPassword = false; FtpTrace.LogIP = true; return(true); } } catch (Exception ex) { Logger.Log(ex); return(false); } }
/// <summary> /// Log to a custom TraceListener /// </summary> private static void LogToCustomListener() { FtpTrace.AddListener(new CustomTraceListener()); }
static void Main(string[] args) { FtpTrace.FlushOnWrite = true; FtpTrace.AddListener(new ConsoleTraceListener()); try { /*foreach (int i in new int[] { * (int)FtpDataConnectionType.EPSV, * (int)FtpDataConnectionType.EPRT, * (int)FtpDataConnectionType.PASV, * (int)FtpDataConnectionType.PORT * }) { * using (FtpClient cl = new FtpClient()) { * cl.Credentials = new NetworkCredential(m_user, m_pass); * cl.Host = m_host; * cl.EncryptionMode = FtpEncryptionMode.None; * cl.ValidateCertificate += new FtpSslValidation(cl_ValidateCertificate); * cl.DataConnectionType = (FtpDataConnectionType)i; * //cl.Encoding = System.Text.Encoding.Default; * cl.Connect(); * Upload(cl); * Download(cl); * Delete(cl); * } * }*/ //StreamResponses(); //TestServer(); //TestManualEncoding(); //TestServer(); //TestDisposeWithMultipleThreads(); //TestMODCOMP_PWD_Parser(); //TestDispose(); //TestHash(); //TestNameListing(); //TestNameListingFTPS(); //TestOpenVMSParser(); // TestIISParser(); //GetMicrosoftFTPListing(); //TestReset(); //TestUTF8(); //TestDirectoryWithDots(); //TestUnixListParser(); // TestFileZillaKick(); //TestUnixList(); //TestNetBSDServer(); // TestConnectionFailure(); //TestGetObjectInfo(); //TestFtpPath(); //TestUnixListing(); //TestListPath(); //TestListPathWithHttp11Proxy(); //TestUploadDownloadFile(); //TestUploadDownloadManyFiles(); //TestUploadDownloadZeroLenFile(); //TestListSpacedPath(); //TestUploadDownloadManyFiles2(); TestFilePermissions(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.WriteLine("--DONE--"); // Console.ReadKey(); }
public void LogToCustomListener() { FtpTrace.AddListener(new CustomTraceListener()); }
static void Main(string[] args) { FtpTrace.LogIP = false; FtpTrace.LogUserName = false; FtpTrace.AddListener(new ConsoleTraceListener()); FtpTrace.AddListener(new TextWriterTraceListener(@"C:\log_file.txt")); try { /*foreach (int i in connectionTypes) { * using (FtpClient cl = new FtpClient()) { * cl.Credentials = new NetworkCredential(m_user, m_pass); * cl.Host = m_host; * cl.EncryptionMode = FtpEncryptionMode.None; * cl.ValidateCertificate += new FtpSslValidation(cl_ValidateCertificate); * cl.DataConnectionType = (FtpDataConnectionType)i; * //cl.Encoding = System.Text.Encoding.Default; * cl.Connect(); * Upload(cl); * Download(cl); * Delete(cl); * } * }*/ //-------------------------------- // MISC //-------------------------------- //StreamResponses(); //TestServer(); //TestManualEncoding(); //TestServer(); //TestDisposeWithMultipleThreads(); //TestMODCOMP_PWD_Parser(); //TestDispose(); //TestHash(); //TestReset(); //TestUTF8(); //TestDirectoryWithDots(); //TestNameListing(); //TestNameListingFTPS(); // TestFileZillaKick(); //TestUnixList(); //TestNetBSDServer(); // TestConnectionFailure(); //TestFtpPath(); //TestListPath(); //TestListPathWithHttp11Proxy(); //TestFileExists(); //TestDeleteDirectory(); //TestMoveFiles(); //-------------------------------- // PARSING //-------------------------------- //TestUnixListParser(); //TestIISParser(); //TestOpenVMSParser(); //-------------------------------- // FILE LISTING //-------------------------------- //TestGetObjectInfo(); TestGetListing(); //TestGetMachineListing(); //GetPublicFTPServerListing(); //TestListSpacedPath(); //TestFilePermissions(); //-------------------------------- // UPLOAD / DOWNLOAD //-------------------------------- //TestUploadDownloadFile(); //TestUploadDownloadManyFiles(); //TestUploadDownloadZeroLenFile(); //TestUploadDownloadManyFiles2(); //TestUploadDownloadFile_UTF(); //TestUploadDownloadFile_ANSI(); //Async Tests #if (CORE || NETFX45) TestAsyncMethods(); #endif } catch (Exception ex) { FtpTrace.WriteLine(ex.ToString()); } FtpTrace.WriteLine("--DONE--"); // Console.ReadKey(); }
public NetFtpFileStorage(Context context, ICertificateValidationHandler app) { _app = app; traceStream = new MemoryStream(); FtpTrace.AddListener(new System.Diagnostics.TextWriterTraceListener(traceStream)); }
static void Main(string[] args) { FtpTrace.FlushOnWrite = true; FtpTrace.AddListener(new ConsoleTraceListener()); try { /*foreach (int i in connectionTypes) { * using (FtpClient cl = new FtpClient()) { * cl.Credentials = new NetworkCredential(m_user, m_pass); * cl.Host = m_host; * cl.EncryptionMode = FtpEncryptionMode.None; * cl.ValidateCertificate += new FtpSslValidation(cl_ValidateCertificate); * cl.DataConnectionType = (FtpDataConnectionType)i; * //cl.Encoding = System.Text.Encoding.Default; * cl.Connect(); * Upload(cl); * Download(cl); * Delete(cl); * } * }*/ //StreamResponses(); //TestServer(); //TestManualEncoding(); //TestServer(); //TestDisposeWithMultipleThreads(); //TestMODCOMP_PWD_Parser(); //TestDispose(); //TestHash(); //TestNameListing(); //TestNameListingFTPS(); //TestOpenVMSParser(); // TestIISParser(); //GetMicrosoftFTPListing(); //TestReset(); //TestUTF8(); //TestDirectoryWithDots(); //TestUnixListParser(); // TestFileZillaKick(); //TestUnixList(); //TestNetBSDServer(); // TestConnectionFailure(); //TestGetObjectInfo(); //TestFtpPath(); //TestUnixListing(); //TestListPath(); //TestListPathWithHttp11Proxy(); //TestUploadDownloadFile(); //TestUploadDownloadManyFiles(); //TestUploadDownloadZeroLenFile(); //TestListSpacedPath(); //TestUploadDownloadManyFiles2(); TestUploadDownloadFile_UTF(); //TestUploadDownloadFile_ANSI(); //TestFilePermissions(); //Async Tests Console.WriteLine("Running Async Tests"); List <Task> tasks = new List <Task>() { TestListPathAsync(), StreamResponsesAsync(), TestGetObjectInfoAsync(), TestHashAsync(), TestUploadDownloadFileAsync(), TestUploadDownloadManyFilesAsync(), TestUploadDownloadManyFiles2Async() }; Task.WhenAll(tasks).ContinueWith(t => { Console.Write("Async Tests Completed: "); if (t.IsFaulted) { var exceptions = FlattenExceptions(t.Exception); Console.WriteLine("With {0} Error{1}.", exceptions.Length, exceptions.Length > 1 ? "s" : ""); for (int i = 0; i > exceptions.Length; i++) { var ex = exceptions[i]; Console.WriteLine("\nException {0}: {1} - {2}", i, ex.GetType().Name, ex.Message); Console.WriteLine(ex.StackTrace); } } else { Console.WriteLine("Successfully"); } }).Wait(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.WriteLine("--DONE--"); // Console.ReadKey(); }
//public void download_US60_SalesListPrice() //{ // //DataAccess dataAccessObj = new DataAccess(); // dataAccessObj = new DataAccess(); // logger = new Logger(); // FtpTrace.AddListener(new TextWriterTraceListener(dataAccessObj.GetFtpLogsPath() + DateTime.Now.ToString("yyyyMMdd_hhmmss") + "FtpLog.txt")); // FtpTrace.LogUserName = true; //false - hide FTP user name in log // FtpTrace.LogPassword = false; //false - hide FTP password in log // FtpTrace.LogIP = true; //false - hide FTP server IP address in log // try // { // using (ObjFtpClient = new FtpClient()) // { // // ObjFtpClient.Host = "k3ftp.akad.kaercher.com"; // ObjFtpClient.Host = dataAccessObj.GetFtpHostName(); // // ObjFtpClient.Credentials = new NetworkCredential("us6trans", "feriefie"); // ObjFtpClient.Credentials = new NetworkCredential(dataAccessObj.GetFtpUserName(), dataAccessObj.GetFtpPassword()); // ObjFtpClient.EncryptionMode = FtpEncryptionMode.Explicit; //534 Policy requires SSL. // ObjFtpClient.SslProtocols = SslProtocols.Tls; // ObjFtpClient.ValidateCertificate += new FtpSslValidation(OnValidateCertificate); // //ObjFtpClient.DataConnectionType = FtpDataConnectionType.PASV; // ObjFtpClient.Connect(); // if (ObjFtpClient.IsConnected) // { // //label1.Text = "Connected!"; // // logger.Log("Server Connected " + DateTime.Now.ToString(), LogLevel.INFORMATION); // foreach (FtpListItem item in ObjFtpClient.GetListing()) // { // // This loop would log all files/directories present at /(root) level on server; see ftp log // // To Disply the modified time (UTC and MST) of the file on server(Default - UTC time zone ) - 13022019 // if (item.Type == FtpFileSystemObjectType.File) // { // if (item.FullName == "/US60_SALES_LISTPRICE.txt") // { // DateTime time_srv = ObjFtpClient.GetModifiedTime(item.FullName); // getFileTimeStampOnServer = time_srv.ToUniversalTime().ToString("MM/dd/yyyy h:mm tt") + " UTC"; // we got the file's timestamp here in UTC. // //Now we need the equivalent in MST // string disp_US_time_zone_srv = string.Empty; // TimeZoneInfo getUS_TimeZoneInfo_srv; // DateTime US_dateTime_srv; // getUS_TimeZoneInfo_srv = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time"); // US_dateTime_srv = TimeZoneInfo.ConvertTime(time_srv.ToUniversalTime(), getUS_TimeZoneInfo_srv); // if (getUS_TimeZoneInfo_srv.IsDaylightSavingTime(US_dateTime_srv)) // { // disp_US_time_zone_srv = getUS_TimeZoneInfo_srv.DaylightName; // } // else // { // disp_US_time_zone_srv = getUS_TimeZoneInfo_srv.StandardName; // } // getFileTimeStampOnServer_US_TIME = US_dateTime_srv.ToString("MM/dd/yyyy h:mm tt") + " " + ((disp_US_time_zone_srv == "Mountain Standard Time") ? "MST" : "MDT"); // } // } // } // //ObjFtpClient.FileExists("/US60_Customer"); // //ObjFtpClient.GetChmod("/US60_Customer"); // //ObjFtpClient.GetFilePermissions("/US60_Customer"); // //string FileToDownload = "/US60_SALES_LISTPRICE.txt"; // string FileToDownload = "/" + dataAccessObj.GetOnlyFileName(); // // if (ObjFtpClient.FileExists("/US60_SALES_LISTPRICE.txt")) // if (ObjFtpClient.FileExists(FileToDownload)) // { // // string downloaded_FileNameFormat = DateTime.Now.ToString("yyyyMMdd_hhmmss") + "_US60_SALES_LISTPRICE" + ".txt"; // //ObjFtpClient.DownloadFile(dataAccessObj.GetTextFileName(), "/US60_SALES_LISTPRICE.txt"); // ObjFtpClient.DownloadFile(dataAccessObj.GetTextFileName(), FileToDownload); // //ObjFtpClient.DownloadFile(@"D:\sudhakar\FromNewServer\" + downloadedFileNameFormat, FileToDownload); // //ObjFtpClient.DownloadFile(dataAccessObj.GetFileDownloadPath() + downloaded_FileNameFormat, FileToDownload); // //ObjFtpClient.ConnectTimeout = System.Threading.Timeout.Infinite; // ObjFtpClient.ConnectTimeout = 2 * 60 * 1000; // 2 Min ; Default: 15000 (15 seconds). // logger.Log("File Downloaded " + DateTime.Now.ToString(), LogLevel.INFORMATION); // // logger.Log("File Downloaded at " + dataAccessObj.GetTextFileName() + " " + DateTime.Now.ToString(), LogLevel.INFORMATION); // } // else // { // logger.Log("File Name : " + dataAccessObj.GetOnlyFileName() + " - File not Found on Server - download_US60_SalesListPrice()", LogLevel.ERR); // throw new FtpException("FTP Client - File not found on server - "+FileToDownload); // } // } // else // { // //label1.Text = "Unable to connect!"; // logger.Log("Unable to Connect Server - download_US60_SalesListPrice() " + DateTime.Now.ToString(), LogLevel.FATAL); // throw new FtpException("FTP Client - Not Connected"); // } // } // } // catch (Exception ex) // { // //logger.Log(ex.Message, LogLevel.FATAL); // throw new FtpException(ex.Message); // } //} /* New Mar 25 2019 */ public void DownloadTheFile(string file_ToDownload) { //DataAccess dataAccessObj = new DataAccess(); dataAccessObj = new DataAccess(); logger = new Logger(); FtpTrace.AddListener(new TextWriterTraceListener(dataAccessObj.GetFtpLogsPath() + DateTime.Now.ToString("yyyyMMdd_hhmmss") + "FtpLog.txt")); FtpTrace.LogUserName = true; //false - hide FTP user name in log FtpTrace.LogPassword = false; //false - hide FTP password in log FtpTrace.LogIP = true; //false - hide FTP server IP address in log try { using (ObjFtpClient = new FtpClient()) { // ObjFtpClient.Host = "k3ftp.akad.kaercher.com"; ObjFtpClient.Host = dataAccessObj.GetFtpHostName(); // ObjFtpClient.Credentials = new NetworkCredential("us6trans", "feriefie"); ObjFtpClient.Credentials = new NetworkCredential(dataAccessObj.GetFtpUserName(), dataAccessObj.GetFtpPassword()); ObjFtpClient.EncryptionMode = FtpEncryptionMode.Explicit; //534 Policy requires SSL. ObjFtpClient.SslProtocols = SslProtocols.Tls; ObjFtpClient.ValidateCertificate += new FtpSslValidation(OnValidateCertificate); //ObjFtpClient.DataConnectionType = FtpDataConnectionType.PASV; ObjFtpClient.Connect(); if (ObjFtpClient.IsConnected) { //label1.Text = "Connected!"; // logger.Log("Server Connected " + DateTime.Now.ToString(), LogLevel.INFORMATION); foreach (FtpListItem item in ObjFtpClient.GetListing()) { // This loop would log all files/directories present at /(root) level on server; see ftp log // To Disply the modified time (UTC and MST) of the file on server(Default - UTC time zone ) - 13022019 if (item.Type == FtpFileSystemObjectType.File) { //if (item.FullName == "/US60_SALES_LISTPRICE.txt") //25Mar2019 if (item.FullName == "/" + file_ToDownload) { DateTime time_srv = ObjFtpClient.GetModifiedTime(item.FullName); getFileTimeStampOnServer = time_srv.ToUniversalTime().ToString("MM/dd/yyyy h:mm tt") + " UTC"; // we got the file's timestamp here in UTC. //Now we need the equivalent in Mountain Time -MST string disp_US_time_zone_srv = string.Empty; TimeZoneInfo getUS_TimeZoneInfo_srv; DateTime US_dateTime_srv; getUS_TimeZoneInfo_srv = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time"); US_dateTime_srv = TimeZoneInfo.ConvertTime(time_srv.ToUniversalTime(), getUS_TimeZoneInfo_srv); if (getUS_TimeZoneInfo_srv.IsDaylightSavingTime(US_dateTime_srv)) { disp_US_time_zone_srv = getUS_TimeZoneInfo_srv.DaylightName; } else { disp_US_time_zone_srv = getUS_TimeZoneInfo_srv.StandardName; } getFileTimeStampOnServer_US_TIME = US_dateTime_srv.ToString("MM/dd/yyyy h:mm tt") + " " + ((disp_US_time_zone_srv == "Mountain Standard Time") ? "MST" : "MDT"); } } } //ObjFtpClient.FileExists("/US60_Customer"); //ObjFtpClient.GetChmod("/US60_Customer"); //ObjFtpClient.GetFilePermissions("/US60_Customer"); //string FileToDownload = "/US60_SALES_LISTPRICE.txt"; //string FileToDownload = "/" + dataAccessObj.GetOnlyFileName(); //25Mar2019 string FileToDownload = "/" + file_ToDownload; // if (ObjFtpClient.FileExists("/US60_SALES_LISTPRICE.txt")) if (ObjFtpClient.FileExists(FileToDownload)) { // string downloaded_FileNameFormat = DateTime.Now.ToString("yyyyMMdd_hhmmss") + "_US60_SALES_LISTPRICE" + ".txt"; //ObjFtpClient.DownloadFile(dataAccessObj.GetTextFileName(), "/US60_SALES_LISTPRICE.txt"); if (file_ToDownload == dataAccessObj.GetOnlyFileName()) { ObjFtpClient.DownloadFile(dataAccessObj.GetTextFileName(), FileToDownload); } if (file_ToDownload == dataAccessObj.GetOnlyFileName_IOMATERIALCOST()) { ObjFtpClient.DownloadFile(dataAccessObj.GetTextFileName_IOM(), FileToDownload); } //ObjFtpClient.DownloadFile(@"D:\sudhakar\FromNewServer\" + downloadedFileNameFormat, FileToDownload); //ObjFtpClient.DownloadFile(dataAccessObj.GetFileDownloadPath() + downloaded_FileNameFormat, FileToDownload); //ObjFtpClient.ConnectTimeout = System.Threading.Timeout.Infinite; ObjFtpClient.ConnectTimeout = 2 * 60 * 1000; // 2 Min ; Default: 15000 (15 seconds). logger.Log("File Downloaded : " + file_ToDownload + " - " + DateTime.Now.ToString(), LogLevel.INFORMATION); // logger.Log("File Downloaded at " + dataAccessObj.GetTextFileName() + " " + DateTime.Now.ToString(), LogLevel.INFORMATION); } else { //logger.Log("File Name : " + dataAccessObj.GetOnlyFileName() + " - File not Found on Server - download_US60_SalesListPrice()", LogLevel.ERR); logger.Log("File Name : " + file_ToDownload + " - File not Found on Server - download_US60_SalesListPrice()", LogLevel.ERR); throw new FtpException("FTP Client - File not found on server - " + FileToDownload); } } else { //label1.Text = "Unable to connect!"; logger.Log("Unable to Connect Server - DownloadTheFile() " + DateTime.Now.ToString(), LogLevel.FATAL); throw new FtpException("FTP Client - Not Connected"); } } } catch (Exception ex) { //logger.Log(ex.Message, LogLevel.FATAL); throw new FtpException(ex.Message); } }