Hi Sir ,
I am facing one error. Actually i want to download the file from FTP Server. The following Scenario of FTP server -
FTP Server - ftp://10.10.147.38/
FTP Floder -UploadToDMS/139459
Filename -139459_AE_IE_SC Contract_V33.pdf
I have download the file as provided your code but i am getting some error in following line.
//Fetch the Response and read it into a MemoryStream object.
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Error name - 530 User cannot log in.
Requested to you please provide the solution.
I have also save FTP file path in our database: -ftp://10.10.147.38/UploadToDMS/139459/139459_AE_IE_SC Contract_V33.pdf
protected void DownloadFile(object sender, EventArgs e)
{
string ftp = "ftp://15.16.45.54/";
string ftpFolder = "UploadToDMS/132322/";
string fileName = "132322_AE_IE_SC Contract-V01-cgip.pdf";
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.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)
{
throw new Exception((ex.Response as FtpWebResponse).StatusDescription);
}
}