public FtpDirInfo GetDirectoryContent(string ftpPath, bool recursive = false) { var filelist = GetFileList(ftpPath).OrderByDescending(s => s.Length).ToArray(); var details = GetFileListDetail(ftpPath).ToList(); var result = new FtpDirInfo { FullPath = ftpPath }; foreach (var filename in filelist) { // HACK here... but shh, that works quite smooth ow var fullInfo = details.FirstOrDefault(dir => dir.EndsWith(" " + filename)); if (fullInfo == null) { Log.Warning("Couldn't verify file {0} on server.".Expand(filename)); continue; } // remove it from list - this must be here (because of conflict with suffix errors like a.php and aa.php) details.Remove(fullInfo); if (fullInfo.StartsWith("d")) { if (recursive) { result.AddDirectory(GetDirectoryContent(ftpPath.CombineFtp(filename)), fullInfo); } else { result.AddDirectory(filename, fullInfo); } } else { result.AddFile(filename, fullInfo); } } return(result); }
public void DeleteDirectory(FtpDirInfo ftpDir, bool deleteRoot = true) { if (!ftpDir.IsEmpty()) { foreach (var file in ftpDir.Files) { DeleteFile(file.FileName); } foreach (var dir in ftpDir.Directories) { DeleteDirectory(GetDirectoryContent(dir.FullPath, false)); } } if (deleteRoot) { DeleteEmptyDirectory(ftpDir.FullPath); } }