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; } }
public async Task <bool> connect() { if (secureMode) { await ftpClient.AutoConnectAsync(); } else { await ftpClient.ConnectAsync(); } return(ftpClient.IsConnected); }
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); } }