{"id":326416,"date":"2021-07-14T09:00:14","date_gmt":"2021-07-14T09:00:14","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=326416"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=326416","title":{"rendered":"\u041e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ftp \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 Fluent interface"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d <a href=\"https:\/\/martinfowler.com\/bliki\/FluentInterface.html\" rel=\"noopener noreferrer nofollow\">Fluent interface<\/a>, \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0438 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 ftp. \u0417\u0430\u0434\u0430\u0447\u0430, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0432 \u043f\u043e\u0442\u043e\u043a\/\u0444\u0430\u0439\u043b;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430\/\u0444\u0430\u0439\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u044f\u0442\u044c \u0444\u0430\u0439\u043b\u044b;<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438(ip, port, login, name).<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c, \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <strong>IntelliSense <\/strong>\u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043b\u0435\u0433\u043a\u043e\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430.  \u041f\u0440\u0438\u043c\u0435\u0440: <\/p>\n<pre><code class=\"cs\">_ftpService   .OnConfigurate(pathSource)   .Download(file)   .ToFile(localFile);<\/code><\/pre>\n<p>\u0438\/\u0438\u043b\u0438<\/p>\n<pre><code class=\"cs\">_ftpService   .OnConfigurate(pathSource)   .Download(file)   .ToSteam(memStream);<\/code><\/pre>\n<p>\u0438\/\u0438\u043b\u0438<\/p>\n<pre><code class=\"cs\"> _ftpService     .OnConfigurate(pathDestination)     .Upload(fileNameDestination)   \t.FromStream(memStream);<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c SRP(\u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438):<\/p>\n<pre><code class=\"cs\">\/\/\/ &lt;summary&gt; \/\/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0444\u0442\u043f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \/\/\/ &lt;\/summary&gt; public interface ITransferFileService {   string Url { get; }   ITransferServiceAction OnConfigurate(string path); }    \/\/\/ &lt;summary&gt; \/\/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0444\u0442\u043f \/\/\/ &lt;\/summary&gt; public interface ITransferServiceWrite {   void FromFile(string filePath);   void FromStream(Stream stream); }    \/\/\/ &lt;summary&gt; \/\/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0447\u0442\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0444\u0442\u043f \/\/\/ &lt;\/summary&gt; public interface ITransferServiceRead {   void ToFile(string filePath);   void ToStream(Stream stream); }     \/\/\/ &lt;summaty&gt; \/\/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u0444\u0442\u043f \/\/\/ &lt;\/summary&gt; public interface ITransferServiceAction {   ITransferServiceRead Download(string fileName);   ITransferServiceWrite Upload(string fileName);   void Delete(string fileName);   IEnumerable&lt;string&gt; GetNameFiles(); }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432.<\/p>\n<pre><code class=\"cs\">public class FtpService :  \t\tITransferFileService, \t\tITransferServiceAction, \t\tITransferServiceRead, \t\tITransferServiceWrite \t{ \t\tprivate readonly Logger _logger; \t \t\tprivate string _fileName;  \t\tpublic FtpService(string url, ILogger logger) \t\t{ \t\t\t_logger = logger; \t\t\tUrl = url; \t\t}      \t\tpublic string Url { get; }  \t\t\/\/\/ &lt;summary&gt; \t\t\/\/\/ \u041f\u043e\u0440\u0442(\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 21) \t\t\/\/\/ &lt;\/summary&gt; \t\tpublic int Port { get; private set; } = 21; \t\t \t\t\/\/\/ &lt;summary&gt; \t\t\/\/\/ \u041f\u0430\u0440\u043e\u043b\u044c \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0444\u0442\u043f \t\t\/\/\/ &lt;\/summary&gt; \t\tprivate string Password { get; set; }  \t\t\/\/\/ &lt;summary&gt; \t\t\/\/\/ \u041b\u043e\u0433\u0438\u043d \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u0442\u043f \t\t\/\/\/ &lt;\/summary&gt; \t\tprivate string Login { get; set;}  \t\t\/\/\/ &lt;summary&gt; \t\t\/\/\/ \u041f\u0443\u0442\u044c \t\t\/\/\/ &lt;\/summary&gt; \t\tprivate string Path { get; set; }   \t\tpublic void SetCredential(string login, string password) \t\t{ \t\t\tLogin = login; \t\t\tPassword = password; \t\t}  \t\tpublic ITransferServiceAction OnConfigurate(string path) \t\t{ \t\t\tPath = path; \t\t\treturn this; \t\t}  \t\tpublic ITransferServiceRead Download(string fileName) \t\t{ \t\t\t_fileName = fileName; \t\t\treturn this; \t\t}  \t\tpublic ITransferServiceWrite Upload(string fileName) \t\t{ \t\t\t_fileName = fileName; \t\t\treturn this; \t\t}  \t\tpublic void Delete(string fileName) \t\t{ \t\t\ttry \t\t\t{ \t\t\t\tvar request = (FtpWebRequest) WebRequest.Create($\"{Url}\/{Path}\/{_fileName}\");  \t\t\t\trequest.Credentials = new NetworkCredential(Login,Password);  \t\t\t\trequest.Method = WebRequestMethods.Ftp.DeleteFile; \t\t\t\trequest.GetResponse(); \t\t\t} \t\t\tcatch (Exception ex) \t\t\t{ \t\t\t\t_logger.Error($\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0441 ftp \u0441\u0435\u0440\u0432\u0435\u0440\u0430 - {ex.Message} \"); \t\t\t} \t\t}  \t\tpublic void FromFile(string filePath) \t\t{ \t\t\tif(string.IsNullOrEmpty(filePath)) \t\t\t\treturn;  \t\t\ttry \t\t\t{ \t\t\t\tusing (var client = new WebClient()) \t\t\t\t{ \t\t\t\t\tclient.Credentials = new NetworkCredential(Login, Password); \t\t\t\t\tclient.UploadFile($\"{Url}\/{Path}\/{_fileName}\", WebRequestMethods.Ftp.UploadFile, filePath); \t\t\t\t} \t\t\t} \t\t\tcatch (Exception ex) \t\t\t{ \t\t\t\t_logger.Error(ex); \t\t\t} \t\t\t \t\t}  \t\tpublic void FromStream(Stream stream) \t\t{ \t\t\tif(stream == null) \t\t\t\treturn; \t\t\ttry \t\t\t{ \t\t\t\tvar request = \t\t\t\t\t(FtpWebRequest)WebRequest.Create($\"{Url}\/{Path}\/{_fileName}\"); \t\t\t\trequest.Credentials = new NetworkCredential(Login, Password); \t\t\t\trequest.UsePassive = true; \t\t\t\trequest.UsePassive = true; \t\t\t\trequest.KeepAlive = true; \t\t\t\trequest.Method = WebRequestMethods.Ftp.UploadFile;   \t\t\t \t\t\t\tusing (var ftpStream = request.GetRequestStream()) \t\t\t\t{ \t\t\t\t\tstream.CopyTo(ftpStream); \t\t\t\t} \t\t\t\trequest.GetResponse(); \t\t\t} \t\t\tcatch (Exception ex) \t\t\t{ \t\t\t\t_logger.Error(ex); \t\t\t} \t\t}  \t\tprivate byte[] DownloadFile() \t\t{ \t\t\tvar ftpRequest = (FtpWebRequest)WebRequest.Create($\"{Url}\/{Path}\/{_fileName}\"); \t\t\tftpRequest.Credentials = new NetworkCredential(Login, Password); \t\t\tftpRequest.UseBinary = true; \t\t\tftpRequest.UsePassive = true; \t\t\tftpRequest.KeepAlive = true; \t\t\tftpRequest.Method = WebRequestMethods.Ftp.DownloadFile; \t\t\tvar ftpResponse = (FtpWebResponse)ftpRequest.GetResponse(); \t\t\tusing (var ms = new MemoryStream()) \t\t\t{ \t\t\t\tftpResponse.GetResponseStream().CopyTo(ms); \t\t\t\treturn ms.ToArray(); \t\t\t} \t\t}  \t\tpublic void ToFile(string filePath) \t\t{ \t\t\ttry \t\t\t{ \t\t\t\tvar downloadedFile = DownloadFile(); \t\t\t\tFile.WriteAllBytes(filePath, downloadedFile); \t\t\t} \t\t\tcatch (WebException ex) \t\t\t{ \t\t\t\t_logger.Error(Url); \t\t\t\t_logger.Error(ex); \t\t\t} \t\t}  \t\tpublic void ToStream(Stream stream) \t\t{ \t\t\tif (stream == null) \t\t\t\treturn;  \t\t\ttry \t\t\t{ \t\t\t\tusing (var writer = new BinaryWriter(stream)) \t\t\t\t{ \t\t\t\t\tvar downloadedFile = DownloadFile(); \t\t\t\t\twriter.Write(downloadedFile); \t\t\t\t} \t\t\t} \t\t\tcatch (WebException ex) \t\t\t{ \t\t\t\t_logger.Error(Url); \t\t\t\t_logger.Error(ex); \t\t\t} \t\t}  \t\tpublic IEnumerable&lt;string&gt; GetNameFiles() \t\t{ \t\t\tvar request = (FtpWebRequest)WebRequest.Create($\"{Url}\/{Path}\"); \t\t\trequest.Method = WebRequestMethods.Ftp.ListDirectory; \t\t\trequest.Credentials = new NetworkCredential(Login, Password); \t\t\tvar files = new List&lt;string&gt;(); \t\t\tusing (var response = (FtpWebResponse)request.GetResponse()) \t\t\t{ \t\t\t\tvar responseStream = response.GetResponseStream(); \t\t\t\tusing (var reader = new StreamReader(responseStream)) \t\t\t\t{ \t\t\t\t\tvar line = reader.ReadLine(); \t\t\t\t\twhile (!string.IsNullOrEmpty(line)) \t\t\t\t\t{ \t\t\t\t\t\ttry \t\t\t\t\t\t{ \t\t\t\t\t\t\tfiles.Add(line); \t\t\t\t\t\t\tline = reader.ReadLine(); \t\t\t\t\t\t} \t\t\t\t\t\tcatch (Exception ex) \t\t\t\t\t\t{ \t\t\t\t\t\t\t_logger.Error(ex); \t\t\t\t\t\t} \t\t\t\t\t} \t\t\t\t} \t\t\t} \t\t\treturn files; \t\t}  \t\tpublic void SetPort(int port) \t\t{ \t\t\tPort = port; \t\t} \t}<\/code><\/pre>\n<p>\u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435 &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0446\u0435\u043f\u043e\u0447\u043a\u0438. \u041d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u043d\u0435\u0442, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043c\u0435\u0442\u043e\u0434\u044b \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0442\u0438\u043f\u043e\u043c Task&lt;T&gt;. \u0414\u043b\u044f \u0433\u0438\u0431\u043a\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c:<\/p>\n<pre><code class=\"cs\">\/\/\/ &lt;summary&gt; \/\/\/ \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c Ftp \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \/\/\/ &lt;\/summary&gt; public class BuilderFtpService {   private FtpService ftpService { get; }    \/\/\/ &lt;summary&gt;   \/\/\/ \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441 ip \u0430\u0434\u0440\u0435\u0441\u043e\u043c   \/\/\/ &lt;\/summary&gt;   \/\/\/ &lt;param name=\"url\"&gt;\u0410\u0434\u0440\u0435\u0441 \u0444\u0442\u043f&lt;\/param&gt;   \/\/\/ &lt;param name=\"logger\"&gt;\u041b\u043e\u0433\u0433\u0435\u0440&lt;\/param&gt;   public BuilderFtpService(string url, ILogger logger)   {     ftpService = new FtpService(url,logger);   }    \/\/\/ &lt;summary&gt;   \/\/\/ \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u0430   \/\/\/ &lt;\/summary&gt;   public ITransferFileService Build() =&gt; ftpService;    \/\/\/ &lt;summary&gt;   \/\/\/ \u0423\u043a\u0430\u0437\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435   \/\/\/ &lt;\/summary&gt;   \/\/\/ &lt;param name=\"login\"&gt;\u041b\u043e\u0433\u0438\u043d&lt;\/param&gt;   \/\/\/ &lt;param name=\"password\"&gt;\u041f\u0430\u0440\u043e\u043b\u044c&lt;\/param&gt;   \/\/\/ &lt;returns&gt;\u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c \u0444\u0442\u043f \u0441\u0435\u0440\u0432\u0438\u0441\u0430&lt;\/returns&gt;   public BuilderFtpService WithCredential(string login, string password)   {     ftpService.SetCredential(login, password);     return this;   }    \/\/\/ &lt;summary&gt;   \/\/\/ \u0423\u043a\u0430\u0437\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435   \/\/\/ &lt;\/summary&gt;   \/\/\/ &lt;param name=\"login\"&gt;\u041b\u043e\u0433\u0438\u043d&lt;\/param&gt;   \/\/\/ &lt;param name=\"password\"&gt;\u041f\u0430\u0440\u043e\u043b\u044c&lt;\/param&gt;   \/\/\/ &lt;returns&gt;\u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c \u0444\u0442\u043f \u0441\u0435\u0440\u0432\u0438\u0441\u0430&lt;\/returns&gt;   public BuilderFtpService WithPort(int port)   {     ftpService.SetPort(port);     return this;   } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">new BuilderFtpService(ipAddress, logger)   .WithCredential(login, password)   .Build()   .OnConfigurate(pathSource)   .Download(file)   .ToFile(localFile);<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 IoC \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b. <\/p>\n<p>\u0422\u0430\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0438\u043c\u0435\u0435\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0432\u0438\u0434, \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430. \u041a\u0430\u043a \u0438 \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435, \u043f\u0430\u0442\u0442\u0435\u0440\u043d fluent interface \u0438\u043c\u0435\u0435\u0442 \u043c\u0438\u043d\u0443\u0441\u044b &#8212; \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0438. \u0412 \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u043a\u0430\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0442\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0443 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438. <\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/567638\/\"> https:\/\/habr.com\/ru\/post\/567638\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d <a href=\"https:\/\/martinfowler.com\/bliki\/FluentInterface.html\" rel=\"noopener noreferrer nofollow\">Fluent interface<\/a>, \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0438 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 ftp. \u0417\u0430\u0434\u0430\u0447\u0430, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0432 \u043f\u043e\u0442\u043e\u043a\/\u0444\u0430\u0439\u043b;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430\/\u0444\u0430\u0439\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u044f\u0442\u044c \u0444\u0430\u0439\u043b\u044b;<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438(ip, port, login, name).<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c, \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <strong>IntelliSense <\/strong>\u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043b\u0435\u0433\u043a\u043e\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430.  \u041f\u0440\u0438\u043c\u0435\u0440: <\/p>\n<pre><code class=\"cs\">_ftpService   .OnConfigurate(pathSource)   .Download(file)   .ToFile(localFile);<\/code><\/pre>\n<p>\u0438\/\u0438\u043b\u0438<\/p>\n<pre><code class=\"cs\">_ftpService   .OnConfigurate(pathSource)   .Download(file)   .ToSteam(memStream);<\/code><\/pre>\n<p>\u0438\/\u0438\u043b\u0438<\/p>\n<pre><code class=\"cs\"> _ftpService     .OnConfigurate(pathDestination)     .Upload(fileNameDestination)   \t.FromStream(memStream);<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c SRP(\u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438):<\/p>\n<pre><code class=\"cs\">\/\/\/ &lt;summary&gt; \/\/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0444\u0442\u043f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \/\/\/ &lt;\/summary&gt; public interface ITransferFileService {   string Url { get; }   ITransferServiceAction OnConfigurate(string path); }    \/\/\/ &lt;summary&gt; \/\/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0444\u0442\u043f \/\/\/ &lt;\/summary&gt; public interface ITransferServiceWrite {   void FromFile(string filePath);   void FromStream(Stream stream); }    \/\/\/ &lt;summary&gt; \/\/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0447\u0442\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0444\u0442\u043f \/\/\/ &lt;\/summary&gt; public interface ITransferServiceRead {   void ToFile(string filePath);   void ToStream(Stream stream); }     \/\/\/ &lt;summaty&gt; \/\/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u0444\u0442\u043f \/\/\/ &lt;\/summary&gt; public interface ITransferServiceAction {   ITransferServiceRead Download(string fileName);   ITransferServiceWrite Upload(string fileName);   void Delete(string fileName);   IEnumerable&lt;string&gt; GetNameFiles(); }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432.<\/p>\n<pre><code class=\"cs\">public class FtpService :  \t\tITransferFileService, \t\tITransferServiceAction, \t\tITransferServiceRead, \t\tITransferServiceWrite \t{ \t\tprivate readonly Logger _logger; \t \t\tprivate string _fileName;  \t\tpublic FtpService(string url, ILogger logger) \t\t{ \t\t\t_logger = logger; \t\t\tUrl = url; \t\t}      \t\tpublic string Url { get; }  \t\t\/\/\/ &lt;summary&gt; \t\t\/\/\/ \u041f\u043e\u0440\u0442(\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 21) \t\t\/\/\/ &lt;\/summary&gt; \t\tpublic int Port { get; private set; } = 21; \t\t \t\t\/\/\/ &lt;summary&gt; \t\t\/\/\/ \u041f\u0430\u0440\u043e\u043b\u044c \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0444\u0442\u043f \t\t\/\/\/ &lt;\/summary&gt; \t\tprivate string Password { get; set; }  \t\t\/\/\/ &lt;summary&gt; \t\t\/\/\/ \u041b\u043e\u0433\u0438\u043d \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u0442\u043f \t\t\/\/\/ &lt;\/summary&gt; \t\tprivate string Login { get; set;}  \t\t\/\/\/ &lt;summary&gt; \t\t\/\/\/ \u041f\u0443\u0442\u044c \t\t\/\/\/ &lt;\/summary&gt; \t\tprivate string Path { get; set; }   \t\tpublic void SetCredential(string login, string password) \t\t{ \t\t\tLogin = login; \t\t\tPassword = password; \t\t}  \t\tpublic ITransferServiceAction OnConfigurate(string path) \t\t{ \t\t\tPath = path; \t\t\treturn this; \t\t}  \t\tpublic ITransferServiceRead Download(string fileName) \t\t{ \t\t\t_fileName = fileName; \t\t\treturn this; \t\t}  \t\tpublic ITransferServiceWrite Upload(string fileName) \t\t{ \t\t\t_fileName = fileName; \t\t\treturn this; \t\t}  \t\tpublic void Delete(string fileName) \t\t{ \t\t\ttry \t\t\t{ \t\t\t\tvar request = (FtpWebRequest) WebRequest.Create($\"{Url}\/{Path}\/{_fileName}\");  \t\t\t\trequest.Credentials = new NetworkCredential(Login,Password);  \t\t\t\trequest.Method = WebRequestMethods.Ftp.DeleteFile; \t\t\t\trequest.GetResponse(); \t\t\t} \t\t\tcatch (Exception ex) \t\t\t{ \t\t\t\t_logger.Error($\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0441 ftp \u0441\u0435\u0440\u0432\u0435\u0440\u0430 - {ex.Message} \"); \t\t\t} \t\t}  \t\tpublic void FromFile(string filePath) \t\t{ \t\t\tif(string.IsNullOrEmpty(filePath)) \t\t\t\treturn;  \t\t\ttry \t\t\t{ \t\t\t\tusing (var client = new WebClient()) \t\t\t\t{ \t\t\t\t\tclient.Credentials = new NetworkCredential(Login, Password); \t\t\t\t\tclient.UploadFile($\"{Url}\/{Path}\/{_fileName}\", WebRequestMethods.Ftp.UploadFile, filePath); \t\t\t\t} \t\t\t} \t\t\tcatch (Exception ex) \t\t\t{ \t\t\t\t_logger.Error(ex); \t\t\t} \t\t\t \t\t}  \t\tpublic void FromStream(Stream stream) \t\t{ \t\t\tif(stream == null) \t\t\t\treturn; \t\t\ttry \t\t\t{ \t\t\t\tvar request = \t\t\t\t\t(FtpWebRequest)WebRequest.Create($\"{Url}\/{Path}\/{_fileName}\"); \t\t\t\trequest.Credentials = new NetworkCredential(Login, Password); \t\t\t\trequest.UsePassive = true; \t\t\t\trequest.UsePassive = true; \t\t\t\trequest.KeepAlive = true; \t\t\t\trequest.Method = WebRequestMethods.Ftp.UploadFile;   \t\t\t \t\t\t\tusing (var ftpStream = request.GetRequestStream()) \t\t\t\t{ \t\t\t\t\tstream.CopyTo(ftpStream); \t\t\t\t} \t\t\t\trequest.GetResponse(); \t\t\t} \t\t\tcatch (Exception ex) \t\t\t{ \t\t\t\t_logger.Error(ex); \t\t\t} \t\t}  \t\tprivate byte[] DownloadFile() \t\t{ \t\t\tvar ftpRequest = (FtpWebRequest)WebRequest.Create($\"{Url}\/{Path}\/{_fileName}\"); \t\t\tftpRequest.Credentials = new NetworkCredential(Login, Password); \t\t\tftpRequest.UseBinary = true; \t\t\tftpRequest.UsePassive = true; \t\t\tftpRequest.KeepAlive = true; \t\t\tftpRequest.Method = WebRequestMethods.Ftp.DownloadFile; \t\t\tvar ftpResponse = (FtpWebResponse)ftpRequest.GetResponse(); \t\t\tusing (var ms = new MemoryStream()) \t\t\t{ \t\t\t\tftpResponse.GetResponseStream().CopyTo(ms); \t\t\t\treturn ms.ToArray(); \t\t\t} \t\t}  \t\tpublic void ToFile(string filePath) \t\t{ \t\t\ttry \t\t\t{ \t\t\t\tvar downloadedFile = DownloadFile(); \t\t\t\tFile.WriteAllBytes(filePath, downloadedFile); \t\t\t} \t\t\tcatch (WebException ex) \t\t\t{ \t\t\t\t_logger.Error(Url); \t\t\t\t_logger.Error(ex); \t\t\t} \t\t}  \t\tpublic void ToStream(Stream stream) \t\t{ \t\t\tif (stream == null) \t\t\t\treturn;  \t\t\ttry \t\t\t{ \t\t\t\tusing (var writer = new BinaryWriter(stream)) \t\t\t\t{ \t\t\t\t\tvar downloadedFile = DownloadFile(); \t\t\t\t\twriter.Write(downloadedFile); \t\t\t\t} \t\t\t} \t\t\tcatch (WebException ex) \t\t\t{ \t\t\t\t_logger.Error(Url); \t\t\t\t_logger.Error(ex); \t\t\t} \t\t}  \t\tpublic IEnumerable&lt;string&gt; GetNameFiles() \t\t{ \t\t\tvar request = (FtpWebRequest)WebRequest.Create($\"{Url}\/{Path}\"); \t\t\trequest.Method = WebRequestMethods.Ftp.ListDirectory; \t\t\trequest.Credentials = new NetworkCredential(Login, Password); \t\t\tvar files = new List&lt;string&gt;(); \t\t\tusing (var response = (FtpWebResponse)request.GetResponse()) \t\t\t{ \t\t\t\tvar responseStream = response.GetResponseStream(); \t\t\t\tusing (var reader = new StreamReader(responseStream)) \t\t\t\t{ \t\t\t\t\tvar line = reader.ReadLine(); \t\t\t\t\twhile (!string.IsNullOrEmpty(line)) \t\t\t\t\t{ \t\t\t\t\t\ttry \t\t\t\t\t\t{ \t\t\t\t\t\t\tfiles.Add(line); \t\t\t\t\t\t\tline = reader.ReadLine(); \t\t\t\t\t\t} \t\t\t\t\t\tcatch (Exception ex) \t\t\t\t\t\t{ \t\t\t\t\t\t\t_logger.Error(ex); \t\t\t\t\t\t} \t\t\t\t\t} \t\t\t\t} \t\t\t} \t\t\treturn files; \t\t}  \t\tpublic void SetPort(int port) \t\t{ \t\t\tPort = port; \t\t} \t}<\/code><\/pre>\n<p>\u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435 &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0446\u0435\u043f\u043e\u0447\u043a\u0438. \u041d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u043d\u0435\u0442, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043c\u0435\u0442\u043e\u0434\u044b \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0442\u0438\u043f\u043e\u043c Task&lt;T&gt;. \u0414\u043b\u044f \u0433\u0438\u0431\u043a\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c:<\/p>\n<pre><code class=\"cs\">\/\/\/ &lt;summary&gt; \/\/\/ \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c Ftp \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \/\/\/ &lt;\/summary&gt; public class BuilderFtpService {   private FtpService ftpService { get; }    \/\/\/ &lt;summary&gt;   \/\/\/ \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441 ip \u0430\u0434\u0440\u0435\u0441\u043e\u043c   \/\/\/ &lt;\/summary&gt;   \/\/\/ &lt;param name=\"url\"&gt;\u0410\u0434\u0440\u0435\u0441 \u0444\u0442\u043f&lt;\/param&gt;   \/\/\/ &lt;param name=\"logger\"&gt;\u041b\u043e\u0433\u0433\u0435\u0440&lt;\/param&gt;   public BuilderFtpService(string url, ILogger logger)   {     ftpService = new FtpService(url,logger);   }    \/\/\/ &lt;summary&gt;   \/\/\/ \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u0430   \/\/\/ &lt;\/summary&gt;   public ITransferFileService Build() =&gt; ftpService;    \/\/\/ &lt;summary&gt;   \/\/\/ \u0423\u043a\u0430\u0437\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435   \/\/\/ &lt;\/summary&gt;   \/\/\/ &lt;param name=\"login\"&gt;\u041b\u043e\u0433\u0438\u043d&lt;\/param&gt;   \/\/\/ &lt;param name=\"password\"&gt;\u041f\u0430\u0440\u043e\u043b\u044c&lt;\/param&gt;   \/\/\/ &lt;returns&gt;\u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c \u0444\u0442\u043f \u0441\u0435\u0440\u0432\u0438\u0441\u0430&lt;\/returns&gt;   public BuilderFtpService WithCredential(string login, string password)   {     ftpService.SetCredential(login, password);     return this;   }    \/\/\/ &lt;summary&gt;   \/\/\/ \u0423\u043a\u0430\u0437\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435   \/\/\/ &lt;\/summary&gt;   \/\/\/ &lt;param name=\"login\"&gt;\u041b\u043e\u0433\u0438\u043d&lt;\/param&gt;   \/\/\/ &lt;param name=\"password\"&gt;\u041f\u0430\u0440\u043e\u043b\u044c&lt;\/param&gt;   \/\/\/ &lt;returns&gt;\u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c \u0444\u0442\u043f \u0441\u0435\u0440\u0432\u0438\u0441\u0430&lt;\/returns&gt;   public BuilderFtpService WithPort(int port)   {     ftpService.SetPort(port);     return this;   } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">new BuilderFtpService(ipAddress, logger)   .WithCredential(login, password)   .Build()   .OnConfigurate(pathSource)   .Download(file)   .ToFile(localFile);<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 IoC \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b. <\/p>\n<p>\u0422\u0430\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0438\u043c\u0435\u0435\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0432\u0438\u0434, \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430. \u041a\u0430\u043a \u0438 \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435, \u043f\u0430\u0442\u0442\u0435\u0440\u043d fluent interface \u0438\u043c\u0435\u0435\u0442 \u043c\u0438\u043d\u0443\u0441\u044b &#8212; \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0438. \u0412 \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u043a\u0430\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0442\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0443 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438. <\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/567638\/\"> https:\/\/habr.com\/ru\/post\/567638\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-326416","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/326416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=326416"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/326416\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}