Try this if it doesn’t work I’ll send another (String Path,String user,String pass):
static List<DirectoryItem> GetDirectoryInformation(string address, string username, string password) {
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(address);
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
List<DirectoryItem> returnValue = new List<DirectoryItem>();
string[] list = null;
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
list = reader.ReadToEnd().Split(new string[] { "\r\n"},StringSplitOptions.RemoveEmptyEntries);
}
foreach (string line in list) {
string data = line;
string date = data.Substring(0, 17);
DateTime dateTime = DateTime.Parse(date);
data = data.Remove(0, 24);
string dir = data.Substring(0, 5);
bool isDirectory = dir.Equals("<dir>", StringComparison.InvariantCultureIgnoreCase);
data = data.Remove(0, 5);
data = data.Remove(0, 10);
string name = data;
DirectoryItem item = new DirectoryItem();
item.BaseUri = new Uri(address);
item.DateCreated = dateTime;
item.IsDirectory = isDirectory;
item.Name = name;
Debug.WriteLine(item.AbsolutePath);
item.Items = item.IsDirectory ? GetDirectoryInformation(item.AbsolutePath, username, password) : null;
returnValue.Add(item);
}
return returnValue;
}
Where is this
List<DirectoryItem>
?– Ari
I didn’t get @Gonçalo Garrido, I don’t know if it’s because I’m using a fragment, I can’t import the classes.
– Ari