0 votes
by (140 points)
edited

My server have drives and folders hierarchy.i need to see all the files,folders and that subfolders on the server like treeview formate for downloading.I am able to connect to server.

please help me.

Applies to: Rebex FTP/SSL

1 Answer

+1 vote
by (148k points)
edited

You can easily construct a tree made of TreeNode objects yourself by calling Ftp object's GetList method repeatedly. Just use a method like this one:

    public static TreeNode GetListTree(Ftp ftp, string folder)
    {
        // create a tree node
        TreeNode node = new TreeNode(folder);

        // save current folder
        string originalFolder = ftp.GetCurrentDirectory();

        // change current directory to the next folder
        ftp.ChangeDirectory(folder);

        // get list of files in the current folder
        FtpList list = ftp.GetList();

        // iterate through the list of files
        foreach (FtpItem item in list)
        {
            TreeNode subNode;
            if (item.IsDirectory)
            {
                // if an item is a directory, construct
                // a tree for it recursively
                subNode = GetListTree(ftp, item.Name);
            }
            else
            {
                // if an item is not a directory,
                // just add it to the tree
                subNode = new TreeNode(item.Name);
            }

            // add the subnode to current node's nodes
            node.Nodes.Add(subNode);
        }

        // go back to the original folder
        ftp.ChangeDirectory(originalFolder);

        return node;
    }

Call this on the folder you wish to appear in the TreeView and add the result to TreeView's Nodes collection.

by (110 points)
edited

If I want to add a key for each node that is a directory node, how can I do that?

by (148k points)
edited

I'm not quite sure what you mean by 'key' in this context, and where would you like to add it. Could you please explain?

...