I have a webproject that run on hosting company , I need to download ftp files to client directory ,my sample code like below ;
string ftp = "ftp://ftp.adress.com/";
string filepath = "d:\\LEM";
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftp+fileName));
reqFTP.Credentials = new NetworkCredential("username","password");
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.UsePassive = false;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream responseStream = response.GetResponseStream();
//string filePath = (Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fileName));
FileStream writeStream = new FileStream(filepath + "\\" + fileName, FileMode.Create);
int Length = 2048;
Byte[] buffer = new Byte[Length];
int bytesRead = responseStream.Read(buffer, 0, Length);
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, Length);
}
writeStream.Close();
response.Close();
}