0 votes

Is there a way to iterate through folders, since you're able to to list all folders/files within the given path?

by

1 Answer

0 votes

You can use recursion or you can use Ftp.Search method:

List<RemoteSearchItem> list = ftp.Search(new RemoteSearchOptions("*", true));

list variable is going to contain files and folders. You can use RemoteSearchItem.IsFolder property to distinguish files and folders.

Given this structure:

Root
    file_in_root.txt
    Folder
        file_in_folder.txt

Here's the unit test fragment that should explain how to use RemoteSearchItem properties:

List<RemoteSearchItem> list = ftp.Search("Root", new RemoteSearchOptions("*.txt", true));

ListAssert.AreEqual(new[] { "Root", "Root", "Root/Folder" }, list.Select(x => x.RemoteFolder));
ListAssert.AreEqual(new[] { "Root/file_in_root.txt", "Root/Folder", "Root/Folder/file_in_folder.txt" }, list.Select(x => x.GetRemotePath()));
ListAssert.AreEqual(new[] { "file_in_root.txt", "Folder", "file_in_folder.txt" }, list.Select(x => x.FtpItem.Name));
by (297k points)
...