private void LoadTestNodes() { var root = new FtpTreeNode("root", "", 21); root.AddDirectory("Folder1"); root.AddDirectory("Folder2"); var node1 = new FtpTreeNode("root", "Folder1", 21) { Text = "Folder1" }; var subnode1 = new FtpTreeNode("root", "Folder1/SubfolderA", 21) { Text = "SubfolderA" }; node1.Directories.Add("SubfolderA"); subnode1.Files.Add("SubfileA"); node1.Nodes.Add(subnode1); node1.AddFile("File1"); node1.AddFile("File2"); var node2 = new FtpTreeNode("root", "Folder2", 21) { Text = "Folder2" }; node2.AddFile("File3"); root.Nodes.Add(node1); root.Nodes.Add(node2); root.Expand(); DirectoryTree.Nodes.Add(root); }
private void LoadSubNodes(FtpTreeNode rootNode) { var uri = Uri.TryCreate(rootNode.FtpPath, UriKind.Absolute, out var tryParseUri) ? tryParseUri : rootNode.Path != Empty ? new UriBuilder("ftp", rootNode.Server, rootNode.Port, rootNode.Path).Uri : new UriBuilder("ftp", rootNode.Server, rootNode.Port).Uri; var uriString = uri.OriginalString; _req = (FtpWebRequest)WebRequest.Create(uri); _req.Credentials = Connection.FtpCred; _req.UsePassive = Connection.Passive; _req.Method = WebRequestMethods.Ftp.ListDirectoryDetails; try { _rsp = (FtpWebResponse)_req.GetResponse(); var streamReader = new StreamReader(_rsp.GetResponseStream() ?? throw new InvalidOperationException(), Encoding.UTF8); var ftpResponse = FtpResponse.ReadFtpLinesToObject(streamReader); //var rspTokens = streamReader.ReadToEnd().Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); //foreach (var str in rspTokens) //{ foreach (var response in ftpResponse) { switch (response.ItemType) { case FileType.Directory: { var subnode = new FtpTreeNode(rootNode.Server, rootNode.Path + "/" + response.FileName, rootNode.Port); subnode.Text = subnode.Directory; rootNode.Nodes.Add(subnode); LoadSubNodes(subnode); //rootNode.AddDirectory(response.FileName); goto case FileType.UpstreamDirectory; //Fallthrough, because it will not work for me, f*****g stupid } case FileType.UpstreamDirectory: rootNode.AddDirectory(response.FileName); break; case FileType.CurrentDirectory: break; case FileType.File: rootNode.AddFile(response.FileName); break; default: throw new ArgumentOutOfRangeException(); } } } catch (WebException wEx) { } }