0 votes
by (460 points)
edited

Hi,

I want to get info about all directories and sub directories and files in those directories and sub directories from a remote folder

Thanks

Applies to: Rebex FTP/SSL

4 Answers

0 votes
by (58.9k points)
edited

Hello, you can retrieve info about all items from the remote directory "dir" (including all files, subdirectories, subdirectories of subdirectories and so on) with the GetItems method as follows:

        Ftp ftp = new Ftp();
        // connect and login

        FtpItemCollection items = ftp.GetItems("/remotepath/dir/*", TraversalMode.Recursive);
        foreach (var item in items) // iterate through the collection
            Console.WriteLine("{0} {1} {2}Bytes", item.Path, item.Modified, item.Length); //use Properites to access the attributes.

        ftp.Disconnect();

The GetItems method can be used also with Sftp class, then it returns SftpItemCollection.

by (460 points)
edited

Hi,

Thanks for your replay. but i don't want download functionality.

Actually my requirement is to know how many folders and sufolders and also how many files in root dir before downloading functinality.

Example remote dir structure :

dir-A --> contains dir-B and file-1 dir-B --> contains dir-C and file-2

and so on

i want all these details.

Thanks & Regards Srinu

by (58.9k points)
edited

Hello, I just updated my original answer above.

by (460 points)
edited

Hi,

Thanks for your guidence

by (58.9k points)
edited

You're welcome.

0 votes
by (180 points)
edited

I have a related question. Is it possible to "combine" item collections so that the item collection is made up from two different GetItems() calls, like the example below. The item list ends up being just the last call, and I understand why. Looking for away around it. Thanks.

Steve

SftpItemCollection list = client.GetItems(
    new Rebex.IO.FileSet("/Volumes/DAM_RAID_1/Internal_Repository/", "*",
                            Rebex.IO.TraversalMode.Recursive));

list = client.GetItems(
    new Rebex.IO.FileSet("/Volumes/DAM_RAID_4/repository2/", "*",
                            Rebex.IO.TraversalMode.Recursive));

Something like this seems to work...

            SftpItemCollection list0 = client.GetItems(new Rebex.IO.FileSet("/Volumes/DAM_RAID_1/Internal_Repository/", "*", Rebex.IO.TraversalMode.Recursive));

            SftpItemCollection list1 = client.GetItems(new Rebex.IO.FileSet("/Volumes/DAM_RAID_4/repository2/", "*", Rebex.IO.TraversalMode.Recursive));
            foreach (SftpItem item in list1) { list0.Add(item); };

But I am not sure it is the best way (obviously no error handling).

0 votes
by (72.7k points)
edited

Copying items from one collection to another as you shown in the second example is correct solution and moreover it is the most speed optimal solution.

You can achieve the similar result with the single GetItems call like this:

// prepare FileSet
Rebex.IO.FileSet set = new FileSet("/Volumes/");
set.Include("DAM_RAID_1/Internal_Repository/");
set.Include("DAM_RAID_4/repository2/");

// use the FileSet to retrieve all wanted items
SftpItemCollection list = client.GetItems(set);

This leads to less speed effective solution, because the base-path for GetItems is "/Volumes/" so more server directories are listed.

0 votes
by (180 points)
edited

Thank you!

This tool is the best thing going. It gives me a way to script against Mac and Unix servers using .NET. Pretty sweet!

...