void LoadDirectory(BrowserFileInfo path, ListDirectoryResult result) { if (path.Path == null) { // special case for drives/mounts foreach (DriveInfo drive in DriveInfo.GetDrives()) { BrowserFileInfo bfiDrive = new BrowserFileInfo(drive); result.Add(bfiDrive); result.MountCount++; } } else if (Directory.Exists(path.Path)) { // get new files DirectoryInfo newDir = new DirectoryInfo(path.Path); // add back (..) entry, if relevant if (newDir.Parent != null) { // has valid parent dir BrowserFileInfo bfiParent = new BrowserFileInfo(newDir.Parent) { Name = "..", Type = FileType.ParentDirectory }; result.Add(bfiParent); } else { // hit top of root so list drives, special case of null path BrowserFileInfo bfiListDrives = new BrowserFileInfo { Path = null, Name = "..", Type = FileType.ParentDirectory, }; result.Add(bfiListDrives); } // dirs foreach (DirectoryInfo di in newDir.GetDirectories()) { BrowserFileInfo bfi = new BrowserFileInfo(di); result.Add(bfi); } // files foreach (FileInfo fi in newDir.GetFiles()) { BrowserFileInfo bfi = new BrowserFileInfo(fi); result.Add(bfi); } } else { result.SetError(string.Format("Directory doesn't exist: {0}", path.Path), null); } }
public ListDirectoryResult ListDirectory(BrowserFileInfo path) { lock (this) { //return this.DoListDirectory(path); ListDirectoryResult result = new ListDirectoryResult(path); String ArgsPscp = ToArgs(this.Session, this.Session.Password, path.Path); RunPscp( result, ArgsPscp, CommandLineOptions.replacePassword(ArgsPscp, "XXXXX"), null, null, (lines) => { // successful list ScpLineParser parser = new ScpLineParser(); foreach (string rawLine in lines) { string line = rawLine.TrimEnd(); BrowserFileInfo fileInfo; if (parser.TryParseFileLine(line, out fileInfo)) { if (fileInfo.Name != ".") { fileInfo.Path = MakePath(path.Path, fileInfo.Name); result.Add(fileInfo); } } } }); return(result); } }
public ListDirectoryResult ListDirectory(BrowserFileInfo path) { lock (this) { //return this.DoListDirectory(path); ListDirectoryResult result = new ListDirectoryResult(path); RunPscp( result, ToArgs(this.Session, this.Session.Password, path.Path), ToArgs(this.Session, "XXXXX", path.Path), null, null, (lines) => { // successful list ScpLineParser parser = new ScpLineParser(); foreach (string rawLine in lines) { string line = rawLine.TrimEnd(); BrowserFileInfo fileInfo; if (parser.TryParseFileLine(line, out fileInfo)) { if (fileInfo.Name != ".") { fileInfo.Path = MakePath(path.Path, fileInfo.Name); result.Add(fileInfo); } } } }); return result; } }