Ejemplo n.º 1
0
        public async Task <byte[]> DownloadAsync(string Path, string Filename)
        {
            try
            {
                if (await _ftpClient.DirectoryExistsAsync(Path))
                {
                    _ftpClient.RetryAttempts = 10;

                    string fullpath = Path + Filename;

                    using (MemoryStream ms = new MemoryStream())
                    {
                        _log.Info($"{FtpTemplateMessage("Download", Filename, "Downloading")}", fullpath);
                        await _ftpClient.DownloadAsync(ms, fullpath, 0);

                        return(ms.ToArray());
                    }
                }
                else
                {
                    _log.Info($"{FtpTemplateMessage("Download", Filename, "Not Exist")}", Path + Filename);
                    throw new Exception("File Not Exist");
                }
            }
            catch (Exception ex)
            {
                _log.Error($"{FtpTemplateMessage("Download", Filename, "throw exception")}", ex);
                throw ex;
            }
        }