Hi,
I was writing to see how to set the request.Method for ftp messages in the OpenNetCF Smart Device. I can open the ftp port but when I try to set the request.Method = WebRequestMethods.Ftp.ListDirectory i get an exception 'System.ArgumentException', "Value does not fall within the expected range."
I would like to get the list of files in a directory. Do you know if this works and what I might be doing wrong? Does the Ftp support the full list of ftp commands? I have included the code below.
Thanks,
using System;
using System.Net;
using System.Text;
using System.IO;
using OpenNETCF.Net;
using OpenNETCF.Net.Ftp;
private static FtpWebRequest request;
private static Stream ftpRequestStream;
public bool DisplayFileFromServer()
{
StringBuilder result = new StringBuilder();
try
{
FtpRequestCreator creator = new FtpRequestCreator();
FtpWebRequest.RegisterPrefix("ftp:", creator);
IPAddress ip = IPAddress.Parse("10.16.48.18");
Uri serverUri = new Uri("ftp://" + ip + "/");
request = (FtpWebRequest) FtpWebRequest.Create(serverUri);
request.Binary = true;
request.Credentials = new NetworkCredential("anonymous", "1");
request.Method = WebRequestMethods.Ftp.ListDirectory;
ftpRequestStream = request.GetRequestStream();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
string line = streamReader.ReadToEnd();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = streamReader.ReadLine();
}
result.Remove(result.ToString().LastIndexOf('\n'), 1);
streamReader.Close();
//response.Close();
return true;
}
catch ( Exception e)
{
return false;
}
}