void ReadFromFtp(IActivityIOPath path, ref Stream result)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConvertSslToPlain(path.Path));
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.UseBinary = true;
request.KeepAlive = true;
request.EnableSsl = EnableSsl(path);
if(path.IsNotCertVerifiable)
{
ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
}
if(path.Username != string.Empty)
{
request.Credentials = new NetworkCredential(path.Username, path.Password);
}
using(var response = (FtpWebResponse)request.GetResponse())
{
using(var ftpStream = response.GetResponseStream())
{
if(ftpStream != null && ftpStream.CanRead)
{
byte[] data = ftpStream.ToByteArray();
result = new MemoryStream(data);
}
else
{
throw new Exception("Fail");
}
}
}
}