static async Task TestUploadDownloadManyFiles2Async() { using (FtpClient cl = new FtpClient()) { cl.Host = m_host; cl.Credentials = new NetworkCredential(m_user, m_pass); cl.EnableThreadSafeDataConnections = false; await cl.ConnectAsync(); // upload many await cl.UploadFilesAsync(new string[] { @"D:\Drivers\test\file0.exe", @"D:\Drivers\test\file1.exe", @"D:\Drivers\test\file2.exe", @"D:\Drivers\test\file3.exe", @"D:\Drivers\test\file4.exe" }, "/public_html/temp/", false); // download many await cl.DownloadFilesAsync(@"D:\Drivers\test\", new string[] { @"/public_html/temp/file0.exe", @"/public_html/temp/file1.exe", @"/public_html/temp/file2.exe", @"/public_html/temp/file3.exe", @"/public_html/temp/file4.exe" }, false); FtpTrace.WriteLine(" ------------- ALL DONE! ------------------"); cl.Dispose(); } }
//[Fact] public void TestNameListingFTPS() { using (FtpClient cl = NewFtpClient()) { cl.ValidateCertificate += OnValidateCertificate; //cl.DataConnectionType = FtpDataConnectionType.PASV; cl.EncryptionMode = FtpEncryptionMode.Explicit; cl.Connect(); //FtpTrace.WriteLine("Sleeping for 10 seconds to force timeout."); //Thread.Sleep(10000); foreach (FtpListItem item in cl.GetListing()) { FtpTrace.WriteLine(item.FullName); //FtpTrace.WriteLine(item.Modified.Kind); //FtpTrace.WriteLine(item.Modified); } } }
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; }
//[Fact] public void TestListPathWithHttp11Proxy() { using (FtpClient cl = new FtpClientHttp11Proxy(new ProxyInfo { Host = "127.0.0.1", Port = 3128, })) // Credential = new NetworkCredential() { FtpTrace.WriteLine("FTPClient::ConnectionType = '" + cl.ConnectionType + "'"); cl.Credentials = new NetworkCredential(m_user, m_pass); cl.Host = m_host; cl.ValidateCertificate += OnValidateCertificate; cl.DataConnectionType = FtpDataConnectionType.PASV; cl.Connect(); foreach (FtpListItem item in cl.GetListing(null, FtpListOption.SizeModify | FtpListOption.ForceNameList)) { FtpTrace.WriteLine(item.Modified.Kind); FtpTrace.WriteLine(item.Modified); } } }
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); }
private async Task TestServerDownloadAsync(FtpClient client, string path) { foreach (FtpListItem i in await client.GetListingAsync(path)) { switch (i.Type) { case FtpFileSystemObjectType.Directory: await TestServerDownloadAsync(client, i.FullName); break; case FtpFileSystemObjectType.File: using (Stream s = await client.OpenReadAsync(i.FullName)) { byte[] b = new byte[8192]; int read = 0; long total = 0; try { while ((read = await s.ReadAsync(b, 0, b.Length)) > 0) { total += read; Console.Write("\r{0}/{1} {2:p} ", total, s.Length, (double)total / (double)s.Length); } Console.Write("\r{0}/{1} {2:p} ", total, s.Length, (double)total / (double)s.Length); } finally { FtpTrace.WriteLine(""); } } break; } } }
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 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); } foreach (var e in Engines) { ((MediaManager)e.MediaManager).Initialize( ArchiveDirectories.FirstOrDefault(a => a.IdArchive == e.IdArchive)); } Logger.Debug("Engines initialized"); }
//[Fact] public async Task TestUploadDownloadManyFilesAsync() { using (var cl = NewFtpClient()) { cl.EnableThreadSafeDataConnections = false; await cl.ConnectAsync(); // 100 K file for (var i = 0; i < 3; i++) { FtpTrace.WriteLine(" ------------- UPLOAD " + i + " ------------------"); await cl.UploadFileAsync(@"D:\Drivers\mb_driver_intel_bootdisk_irst_64_6series.exe", "/public_html/temp/small.txt"); } // 100 K file for (var i = 0; i < 3; i++) { FtpTrace.WriteLine(" ------------- DOWNLOAD " + i + " ------------------"); await cl.DownloadFileAsync(@"D:\Drivers\test\file" + i + ".exe", "/public_html/temp/small.txt"); } FtpTrace.WriteLine(" ------------- ALL DONE! ------------------"); } }
private void TestServerDownload(FtpClient client, string path) { foreach (var i in client.GetListing(path)) { switch (i.Type) { case FtpFileSystemObjectType.Directory: TestServerDownload(client, i.FullName); break; case FtpFileSystemObjectType.File: using (var s = client.OpenRead(i.FullName)) { var b = new byte[8192]; var read = 0; long total = 0; try { while ((read = s.Read(b, 0, b.Length)) > 0) { total += read; Console.Write("\r{0}/{1} {2:p} ", total, s.Length, (double)total / (double)s.Length); } Console.Write("\r{0}/{1} {2:p} ", total, s.Length, (double)total / (double)s.Length); } finally { FtpTrace.WriteLine(""); } } break; } } }
public void TestOpenVMSParser() { FtpListParser parser = new FtpListParser(new FtpClient()); parser.Init("VMS"); string[] sample = new string[] { "411_4114.TXT;1 11 21-MAR-2012 15:17 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "ACT_CC_NAME_4114.TXT;1 30 21-MAR-2012 15:17 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "ACT_CC_NUM_4114.TXT;1 30 21-MAR-2012 15:17 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "ACT_CELL_NAME_4114.TXT;1 113 21-MAR-2012 15:17 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "ACT_CELL_NUM_4114.TXT;1 113 21-MAR-2012 15:17 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "AGCY_BUDG_4114.TXT;1 63 21-MAR-2012 15:17 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "CELL_SUMM_4114.TXT;1 125 21-MAR-2012 15:17 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "CELL_SUMM_CHART_4114.PDF;2 95 21-MAR-2012 10:58 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "DET_4114.TXT;1 17472 21-MAR-2012 15:17 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "DET_4114_000.TXT;1 777 21-MAR-2012 15:18 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "DET_4114_001.TXT;1 254 21-MAR-2012 15:18 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "DET_4114_003.TXT;1 21 21-MAR-2012 15:18 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "DET_4114_006.TXT;1 22 21-MAR-2012 15:18 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "DET_4114_101.TXT;1 431 21-MAR-2012 15:18 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "DET_4114_121.TXT;1 2459 21-MAR-2012 15:18 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "DET_4114_124.TXT;1 4610 21-MAR-2012 15:18 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "DET_4114_200.TXT;1 936 21-MAR-2012 15:18 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)", "TEL_4114.TXT;1 1178 21-MAR-2012 15:19 [TBMS,TBMS_BOSS] (RWED,RWED,,RE)" }; foreach (string s in sample) { FtpListItem item = parser.ParseSingleLine("disk$user520:[4114.2012.Jan]", s, 0, false); if (item != null) { FtpTrace.WriteLine(item); } } }
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); } }
//[Fact] public async Task StreamResponsesAsync() { using (var cl = NewFtpClient()) { cl.EncryptionMode = FtpEncryptionMode.None; cl.ValidateCertificate += OnValidateCertificate; using (var s = (FtpDataStream)await cl.OpenWriteAsync("test.txt")) { var r = s.CommandStatus; FtpTrace.WriteLine(""); FtpTrace.WriteLine("Response to STOR:"); FtpTrace.WriteLine("Code: " + r.Code); FtpTrace.WriteLine("Message: " + r.Message); FtpTrace.WriteLine("Informational: " + r.InfoMessages); r = s.Close(); FtpTrace.WriteLine(""); FtpTrace.WriteLine("Response after close:"); FtpTrace.WriteLine("Code: " + r.Code); FtpTrace.WriteLine("Message: " + r.Message); FtpTrace.WriteLine("Informational: " + r.InfoMessages); } } }
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 static bool Connect(bool OfflineMode = false, string promptedPassword = "") { string[] remoteSystem; 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 = ""; remoteSystem = CurrentSystem.GetValue("system").Split(':'); if (promptedPassword == "") { password = Password.Decode(CurrentSystem.GetValue("password")); } else { password = promptedPassword; } Client = new FtpClient(remoteSystem[0], 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; if (remoteSystem.Length == 2) { Client.Port = int.Parse(remoteSystem[1]); } 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); }
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 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 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(); }
/// <summary> /// Log to a custom TraceListener /// </summary> private static void LogToCustomListener() { FtpTrace.AddListener(new CustomTraceListener()); }
//[Fact] public void TestGetObjectInfo() { using (var client = NewFtpClient()) { FtpTrace.WriteLine(client.GetObjectInfo("/public_html/temp/README.md")); } }
//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); } }
public void LogToCustomListener() { FtpTrace.AddListener(new CustomTraceListener()); }
static void TestGetObjectInfo() { using (FtpClient client = new FtpClient(m_host, m_user, m_pass)) { FtpTrace.WriteLine(client.GetObjectInfo("/public_html/temp/README.md")); } }