Example #1
0
        public async Task <byte[]> GetImage(string fileName)
        {
            try
            {
                var client = new FtpClient(_host, _user, _password)
                {
                    ValidateAnyCertificate = true
                };
                await client.AutoConnectAsync();

                using var stream = new MemoryStream();
                if (!await client.DownloadAsync(stream, fileName))
                {
                    _logger.LogInformation($"Não foi possível fazer o download do arquivo {fileName}");
                }

                await client.DisconnectAsync();

                return(stream.ToArray());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw;
            }
        }
Example #2
0
        public async Task <bool> connect()
        {
            if (secureMode)
            {
                await ftpClient.AutoConnectAsync();
            }
            else
            {
                await ftpClient.ConnectAsync();
            }

            return(ftpClient.IsConnected);
        }
Example #3
0
        public async Task <Stream> OpenReadAsync(string path, CancellationToken cancellationToken = default)
        {
            await _client.AutoConnectAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                return(await _client.OpenReadAsync(path, FtpDataType.Binary, 0, true, cancellationToken).ConfigureAwait(false));
            }
            catch (FtpCommandException e) when(e.CompletionCode == "550")
            {
                throw new BlobNotFoundException(path, e);
            }
        }