Hi,
I am using the beow C# code for downloading the files from FTP. The file gets generated with error text which says.
error message : </H1><PRE>200 Type set to I. 200 PORT Command successful. 550 /ftp.txt: No such file or directory.</PRE></BODY></HTML>
string file = "ftp.txt"; string fileName = @"D:\Test\" + file; FtpWebRequest downloadRequest = (FtpWebRequest)FtpWebRequest.Create(ftp://ServerName+ "/" + file); downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile; //downloadRequest.Credentials = new NetworkCredential("UserName", "Password"); WebProxy myProxy = new WebProxy(); Uri newUri = new Uri(http://ProxyName:ProxyPortNo); // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set. myProxy.Address = newUri; // Create a NetworkCredential object and associate it with the // Proxy property of request object. myProxy.Credentials = new NetworkCredential("USerName", "Password","Domain"); downloadRequest.Proxy = myProxy; FtpWebResponse response = (FtpWebResponse)downloadRequest.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); FileInfo downloadFile = new FileInfo(fileName); FileStream outputStream = new FileStream(fileName, FileMode.Append); Stream ftpStream = response.GetResponseStream(); long cl = response.ContentLength; int bufferSize = 4096; int readCount; byte[] buffer = new byte[bufferSize]; readCount = ftpStream.Read(buffer, 0, bufferSize); MessageBox.Show("Connected: Downloading File"); while (readCount > 0) { outputStream.Write(buffer, 0, readCount); readCount = ftpStream.Read(buffer, 0, bufferSize); //Console.WriteLine(readCount.ToString()); } ftpStream.Close(); outputStream.Close(); response.Close(); MessageBox.Show("Downloading Complete");
Thanks,
Saikat