Hi Sir ,
I am downloading the file from FTP Server but i am facing some error. I have uploading the file to FTP successfully but i have downloaded the file but still facing some error kindly help me.
Error - System.Exception: '550 The system cannot find the file specified.
string fileName = "139459_AE_IE_SC Contract_V32.pdf";
string ftp = "ftp://16.12.133.33/";
string ftpFolder = "UploadToDMS/139459";
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(userName, password);
//request.Credentials = new NetworkCredential("Username", "Password");
request.UsePassive = true;
request.UseBinary = true;
request.EnableSsl = false;
//Fetch the Response and read it into a MemoryStream object.
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
using (MemoryStream stream = new MemoryStream())
{
//Download the File.
response.GetResponseStream().CopyTo(stream);
Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(stream.ToArray());
Response.End();
}
}
catch (WebException ex)
{
//String status = ((FtpWebResponse)ex.Response).StatusDescription;
throw new Exception((ex.Response as FtpWebResponse).StatusDescription);
}
//End FTP