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); } }
/// <summary> /// Sync call to list directory contents /// </summary> /// <param name="session"></param> /// <param name="path"></param> /// <returns></returns> public ListDirectoryResult ListDirectory(SessionData session, BrowserFileInfo path) { ListDirectoryResult result; if (session == null || session.Username == null) { result = new ListDirectoryResult(path); result.ErrorMsg = "Session invalid"; result.StatusCode = ResultStatusCode.Error; } else { string targetPath = path.Path; if (targetPath == null || targetPath == ".") { targetPath = string.Format("/home/{0}", session.Username); Log.InfoFormat("Defaulting path: {0}->{1}", path.Path, targetPath); path.Path = targetPath; } PscpClient client = new PscpClient(this.Options, session); result = client.ListDirectory(path); } return result; }
/// <summary> /// Sync call to list directory contents /// </summary> /// <param name="session"></param> /// <param name="path"></param> /// <returns></returns> public ListDirectoryResult ListDirectory(SessionData session, BrowserFileInfo path) { ListDirectoryResult result; if (session == null || session.Username == null) { result = new ListDirectoryResult(path) { ErrorMsg = "Session invalid", StatusCode = ResultStatusCode.Error }; } else { string targetPath = path.Path; if (targetPath == null || targetPath == ".") { targetPath = string.Format("/home/{0}", session.Username); Log.InfoFormat("Defaulting path: {0}->{1}", path.Path, targetPath); path.Path = targetPath; } PscpClient client = new PscpClient(this.Options, session); result = client.ListDirectory(path); } return(result); }
private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { string msg = string.Format("System error while loading directory: {0}", e.Error.Message); Log.Error(msg, e.Error); this.ViewModel.Status = msg; } else { ListDirectoryResult result = (ListDirectoryResult)e.Result; switch (result.StatusCode) { case ResultStatusCode.RetryAuthentication: // Request login- first login will be initiated from here after failing 1st call to pscp which attemps key based auth AuthEventArgs authEvent = new AuthEventArgs { UserName = this.Session.Username, Password = this.Session.Password }; this.OnAuthRequest(authEvent); if (authEvent.Handled) { // retry listing this.Session.Username = authEvent.UserName; this.Session.Password = authEvent.Password; this.LoadDirectory(result.Path); } break; case ResultStatusCode.Success: // list files string msg = result.MountCount > 0 ? string.Format("{0} items", result.MountCount) : string.Format("{0} files {1} directories", result.FileCount, result.DirCount); this.ViewModel.Status = string.Format("{0} @ {1}", msg, DateTime.Now); this.CurrentPath = result.Path; this.ViewModel.CurrentPath = result.Path.Path; BaseViewModel.UpdateList(this.ViewModel.Files, result.Files); break; case ResultStatusCode.Error: string errMsg = result.ErrorMsg != null ? result.ErrorMsg : result.Error != null ? string.Format("Error listing directory, {0}", result.Error.Message) : "Unknown Error listing directory"; Log.Error(errMsg, result.Error); this.ViewModel.Status = errMsg; break; default: Log.InfoFormat("Unknown result '{0}'", result.StatusCode); break; } } this.ViewModel.BrowserState = BrowserState.Ready; }
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); } }
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BrowserFileInfo targetPath = (BrowserFileInfo)e.Argument; this.BackgroundWorker.ReportProgress(5, "Requesting files for " + targetPath.Path); ListDirectoryResult result = this.Model.ListDirectory(this.Session, targetPath); this.BackgroundWorker.ReportProgress(80, "Remote call complete: " + result.StatusCode); e.Result = result; }
public ListDirectoryResult ListDirectory(SessionData session, BrowserFileInfo path) { Log.InfoFormat("GetFilesForPath, path={0}", path.Path); ListDirectoryResult result = new ListDirectoryResult(path); try { LoadDirectory(path, result); } catch (Exception ex) { result.SetError(null, ex); Log.ErrorFormat("Error loading directory: {0}", ex.Message); } return result; }
public ListDirectoryResult ListDirectory(SessionData session, BrowserFileInfo path) { Log.InfoFormat("GetFilesForPath, path={0}", path.Path); ListDirectoryResult result = new ListDirectoryResult(path); try { LoadDirectory(path, result); } catch (Exception ex) { result.SetError(null, ex); Log.ErrorFormat("Error loading directory: {0}", ex.Message); } 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; } }