string _ftpURL = "testftp.com"; //Host URL or address of the FTP server string _UserName = "username"; //User Name of the FTP server string _Password = "Password"; //Password of the FTP server string _ftpDirectory = "FTP Foldername"; //The directory in FTP server where the files are present string _FileName = "niks.csv"; //File name, which one will be downloaded string _LocalDirectory = "D:\\"; //Local directory where the files will be downloaded DownloadFile(_ftpURL, _UserName, _Password, _ftpDirectory, _FileName, _LocalDirectory); public void DownloadFile(string ftpURL, string UserName, string Password, string ftpDirectory, string FileName, string LocalDirectory) { if (!File.Exists(LocalDirectory + "/" + FileName)) { try { FtpWebRequest requestFileDownload = (FtpWebRequest)WebRequest.Create(ftpURL + "/" + ftpDirectory + "/" + FileName); requestFileDownload.Credentials = new NetworkCredential(UserName, Password); requestFileDownload.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebResponse responseFileDownload = (FtpWebResponse)requestFileDownload.GetResponse(); Stream responseStream = responseFileDownload.GetResponseStream(); FileStream writeStream = new FileStream(LocalDirectory + "/" + FileName, FileMode.Create); int Length = 2048; Byte[] buffer = new Byte[Length]; int bytesRead = responseStream.Read(buffer, 0, Length); while (bytesRead > 0) { writeStream.Write(buffer, 0, bytesRead); bytesRead = responseStream.Read(buffer, 0, Length); } responseStream.Close(); writeStream.Close(); requestFileDownload = null; } catch (Exception ex) { throw ex; } } }
What is NLog? NLog is a flexible and free logging platform for various .NET platforms, including .NET standard. NLog is easy to apply and it includes several targets (database, file, event viewer). Which platform support it? .NET Framework 3.5, 4, 4.5, 4.6 & 4.7 .NET Framework 4 client profile Xamarin Android Xamarin iOS Windows Phone 8 Silver light 4 and 5 Mono 4 ASP.NET 4 (NLog.Web package) ASP.NET Core (NLog.Web.AspNetCore package) .NET Core (NLog.Extensions.Logging package) .NET Standard 1.x - NLog 4.5 .NET Standard 2.x - NLog 4.5 UWP - NLog 4.5 There are several log levels. Fatal : Something terrible occurred; the application is going down Error : Something fizzled; the application might possibly proceed Warn : Something surprising; the application will proceed Info : Normal conduct like mail sent, client refreshed profile and so on. Debug : For troubleshooting; the executed question, the client confirmed, ...
Comments
Post a Comment