You can't just get ftp listings from the Directory class: you have to set up an FTP connection first:
FTPGetListing(@"Username", "Password", "ftp.Images.MyDomain.com");
...
private void FTPGetListing(string user, string password, string ftpURL)
{
string strConnect = string.Format("ftp://{0}", ftpURL);
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(strConnect);
ftp.Credentials = new NetworkCredential(user, password);
ftp.KeepAlive = false;
ftp.Method = WebRequestMethods.Ftp.DownloadFile;
ftp.UseBinary = true;
ftp.Proxy = null;
ftp.UsePassive = false;
List<string> folders, files;
FTPGetFolder(ftp, @"\", out folders, out files);
}
private void FTPGetFolder(FtpWebRequest request, string baseFolder, out List<string> folders, out List<string> files)
{
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string listing = reader.ReadToEnd();
folders = new List<string>();
files = new List<string>();
string[] lines = listing.Split('\n', '\r');
foreach (string line in lines)
{
...
}
reader.Close();
response.Close();
}
[Edit]
Extra tags "</string></string>" removed.
[/Edit]