I am struggling with a small piece of code which I am currently writing. The application is supposed to run once a day and download all files from an ftp server. My problem is:
Although in theory my routine to list the direcoty content runs fine, checks all files and saves them to a list, practical there are 2 errors:
- The listing is html formatted
- I only need the filename and extension
Code
string localPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
List<string> FtpListing = new List<string>();
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(Properties.Settings.Default.FtpUrl);
//request.Proxy = GlobalProxySelection.GetEmptyWebProxy();
request.Credentials = new NetworkCredential(Properties.Settings.Default.FtpUsername, Properties.Settings.Default.FtpPassword);
request.Method = WebRequestMethods.Ftp.ListDirectory;
using (StreamReader streamReader = new StreamReader(request.GetResponse().GetResponseStream()))
{
string fileName = streamReader.ReadLine();
while (fileName != null)
{
FtpListing.Add(fileName);
fileName = streamReader.ReadLine();
}
}
Without proxy it returns html, with the proxy statement uncommented I am getting a The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
error.
Where am I failing here?
/edit: here is a screenshot of the list, where all files should be listed, but instead a complete html file is saved: