/// <inheritdoc />
public byte[]? DownloadFileFromServer(string basePath, string fileName)
{
if (String.IsNullOrWhiteSpace(fileName))
{
throw new ArgumentNullException(nameof(fileName));
}
if (String.IsNullOrWhiteSpace(basePath))
{
throw new ArgumentNullException(nameof(basePath));
}
return(_retryPolicy.Execute(() =>
{
EnsureConnected();
var filePath = GetFileFullPath(basePath, fileName);
if (!_sftpClient.Exists(filePath))
{
_logger.LogWarning($"File \"{filePath}\" not found on SFTP server");
return null;
}
using (var file = _sftpClient.Open(filePath, FileMode.Open))
{
using (var ms = new MemoryStream())
{
file.CopyTo(ms);
return ms.ToArray();
}
}
}));
}