It depends on how do you obtain the FtpList
collection:
- The
Ftp.GetList
method always returns items just from the current directory.
- The
Ftp.GetItems
method retrieves the whole directory hierarchy (including subfolders) by default.
Note: Even here you can enforce browsing just the current directory by calling:
Ftp.GetItems(path, TraversalMode.NonRecursive)
.
Note: You even don't have to calculate the item.Size
of all items - there is a method FtpList.GetTotalSize()
to do it for you.
So to obtain the correct size of all files in the root folder and all its sub-folders, use the following code:
var lst = ftp.GetItems("/*");
Console.WriteLine("Total size: {0}", lst.GetTotalSize());
The same code works as well for the SFTP component.