void ReadFromSftp(IActivityIOPath path, ref Stream result, List<string> filesToCleanup)
{
var sftp = BuildSftpClient(path);
var ftpPath = ExtractFileNameFromPath(path.Path);
try
{
var tempFileName = BuildTempFileName();
filesToCleanup.Add(tempFileName);
var data = sftp.ReadAllBytes(ftpPath);
File.WriteAllBytes(tempFileName, data);
result = new FileStream(tempFileName, FileMode.Open);
sftp.Disconnect();
}
catch(Exception ex)
{
sftp.Disconnect();
sftp.Dispose();
throw new Exception(ex.Message, ex);
}
}