0 votes
by (390 points)
edited

If I calculate the item.Size for all items in a FtpList will that give me the correct size of all files and sub-folders in the root folder path, or do I need to iterate all of the sub-folders to get the proper size for a total download size?

Applies to: Rebex FTP/SSL

1 Answer

+1 vote
by (18.0k points)
edited
 
Best answer

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.

by (390 points)
edited

Thanks Jan. that sure does make life easier. So if I wanted to do a specific folder and all of its sub-folders would I need to write, ftp.GetItems(myPathVariable + "/*")

by (18.0k points)
edited

Yes, exactly.

...