Error Occured - The remote server returned an error: 227 Entering passive mode (190,100,100,31,210,69)
string fileName = (sender as LinkButton).CommandArgument;
string ftp = "ftp://190.100.100.31/";
string ftpFolder = "usr/Log/";
try
{
//Create FTP Request.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp + ftpFolder + fileName);
request.Method = WebRequestMethods.Ftp.DownloadFile;
//Enter FTP Server credentials.
request.Credentials = new NetworkCredential("Administrator", "1234");
request.UsePassive = true;
request.UseBinary = true;
request.EnableSsl = false;
request.UsePassive = true;
//Fetch the Response and read it into a MemoryStream object.
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
using (Stream responseStream = response.GetResponseStream())
{
using (Stream fileStream = new FileStream(@"c:\UserName\File\" + fileName, FileMode.CreateNew))
{
responseStream.CopyTo(fileStream);
}
}
}
catch (WebException ex)
{
throw new Exception((ex.Response as FtpWebResponse).StatusDescription);
}