I am trying to get a list of files on a server
CODE:
string ftpUserID = "user";
string ftpPassword = "password";
string ftpServerIP = "192.###.###.###";
string remoteDirectory = @"\Update\UpdateTest";
string localDirectory = @"C:\Updates";
string[] downloadFiles;
StringBuilder result = new StringBuilder();
WebResponse response = null;
StreamReader reader = null;
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + remoteDirectory));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
reqFTP.EnableSsl = true;
reqFTP.Proxy = null;
reqFTP.KeepAlive = true;
reqFTP.UsePassive = true;
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
result.Remove(result.ToString().LastIndexOf('\n'), 1);
return result.ToString().Split('\n');
I keep getting the WebException error saying 'Unable to connect to the remote server'
This is as a result of errors in :
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + remoteDirectory));
Which is throwing a System.NotSuportedException on the reqFTP.Content and reqFTP.PreAuthenticate parts I think.