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.