private void ListboxDirContents_SelectedIndexChanged(object sender, EventArgs e) { int Idx = ListboxDirContents.SelectedIndex; if (Idx < 0) { return; } string Target = (string)ListboxDirContents.Items[Idx]; bool IsDir = Target.EndsWith("/"); if (IsDir) { string[] AbsPath = Target.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); FtpDirectory NewDir = CurrentDir; for (int i = 0; i < AbsPath.Length; ++i) { NewDir = NewDir.GetSubdirectory(AbsPath[i]); if (NewDir == null) { MessageBox.Show("Internal error: selected directory doesn't exist in memory"); return; } } RequestChangeDirectory(NewDir); } }
private void OnFtpDirectoryListed(bool Success, FtpDirectory Dir) { if (!Success) { Invoke(new Action(() => { MessageBox.Show("Could not list directory"); })); return; } Invoke(new Action(() => { ListboxDirContents.Items.Clear(); foreach (FtpDirectory Sub in Dir.Subdirectories) { ListboxDirContents.Items.Add(Sub.DirName + "/"); } foreach (FtpFile File in Dir.Files) { ListboxDirContents.Items.Add(File.FileName); } MarkInterfaceBusy(false); })); }
private void RequestChangeDirectory(FtpDirectory NewDir) { Invoke(new Action(() => { MarkInterfaceBusy(true); })); FcChangeDirectory Cmd = new FcChangeDirectory(CurrentDir, NewDir); Cmd.OnDirectoryChanged += OnFtpDirectoryChanged; Service.PushNewCommand(Cmd); }
private void ButtonGoUp_Click(object sender, EventArgs e) { FtpDirectory Parent = CurrentDir.GetParentDir(); if (Parent != null) { RequestChangeDirectory(Parent); } }
private void RequestListDirectory(FtpDirectory NewDir) { FcRequestDynamicPort PasvCmd = new FcRequestDynamicPort(); Service.PushNewCommand(PasvCmd); FcListDirectory Cmd = new FcListDirectory(NewDir); Cmd.OnDirectoryListed += OnFtpDirectoryListed; Service.PushNewCommand(Cmd); }
private void ButtonScanRecursive_Click(object sender, EventArgs e) { MarkInterfaceBusy(true); CommandsLeft = 0; ++CommandsLeft; Service.PushNewCommand(new FcRequestDynamicPort()); RecursiveTree = new FtpDirectory(); FcListDirectory Dir = new FcListDirectory(RecursiveTree); Dir.OnDirectoryListed += RecursiveOnDirectoryListed; Service.PushNewCommand(Dir); }
private void OnFtpUserLoggedIn(bool Success) { if (Success) { CurrentDir = new FtpDirectory(); RequestChangeDirectory(CurrentDir); } else { MessageBox.Show("Connection succeeded but login failed.\nCheck your credentials."); DisableService(); } }
private void RecursivePrintDirectory(FtpDirectory Directory) { foreach (FtpDirectory Subdir in Directory.Subdirectories) { RecursivePrintDirectory(Subdir); } ListboxDirContents.Items.Add(Directory.PathString()); foreach (FtpFile File in Directory.Files) { ListboxDirContents.Items.Add(File.GetDirectory().PathString() + File.FileName); } MarkInterfaceBusy(false); }
public FtpDirectory AddSubdirectory(string SubName) { //blokujemy duplikaty FtpDirectory Duplicate = GetSubdirectory(SubName); if (Duplicate != null) { return(Duplicate); } FtpDirectory NewDir = new FtpDirectory(this, SubName); Subdirectories.Add(NewDir); return(NewDir); }
private void OnFtpDirectoryChanged(bool Success, FtpDirectory Dir) { Invoke(new Action(() => { if (!Success) { MessageBox.Show("Could not change to a new directory, keeping current"); } else { LabelCurrentPath.Text = Dir.PathString(); } })); CurrentDir = Dir; RequestListDirectory(CurrentDir); }
private void RecursiveOnDirectoryListed(bool Success, FtpDirectory Directory) { --CommandsLeft; foreach (FtpDirectory Subdir in Directory.Subdirectories) { ++CommandsLeft; Service.PushNewCommand(new FcRequestDynamicPort()); FcListDirectory Dir = new FcListDirectory(Subdir); Dir.OnDirectoryListed += RecursiveOnDirectoryListed; Service.PushNewCommand(Dir); } if (CommandsLeft == 0) { Invoke(new Action(() => { ListboxDirContents.Items.Clear(); CurrentDir = RecursiveTree; RecursivePrintDirectory(RecursiveTree); })); } }
public FtpFile(FtpDirectory Owner, string Name) { OwnerDir = Owner ?? throw new Exception(); FileName = Name; }
public FtpDirectory(FtpDirectory TopDirectory, string Name) { OwnerDir = TopDirectory ?? throw new Exception(); DirName = Name; }
public FcListDirectory(FtpDirectory TargetDir) { CurrentDir = TargetDir; }