This project is read-only.

Listing all files in a folder

Apr 21, 2011 at 11:59 AM



I wonder if there's a way of listing all file and folders inside a directory, including subdirectories. Something like:

Directory.GetFiles("path", "*", SearchOption.AllDirectories);

but for a folder on host.

I know .List() lists all files and folders, but it doesn't list subfolders...

If this can't be done with the latest release, can you please add it in the next release of FTPlib?

Thanks in advance,


Apr 22, 2011 at 2:32 PM

This functionality doesn't currently exist, but you could easily write a method that does it for you:

void PrintDirectories(path)
	foreach(var directory in ftp.GetDirectories(path))
	foreach(var file in ftp.GetFiles(path))



Apr 23, 2011 at 4:38 PM

I tried this, but the app freezes and doesn't respond...

Mar 17, 2013 at 9:09 AM
Edited Mar 17, 2013 at 10:12 AM

I use this code for listing all picture files that place in the selected directory with the specified filter.
public static Dictionary<string, int> ReadSubDirectories(string dirname)
            public static string filters = "*.jpg|*.gif|*.png|*.bmp|*.jpe|"
                            + "*.jpeg|*.wmf|*.emf|*.xbm|*.ico|*.eps|*.tif|*.tiff|"
                            + "*.g01|*.g02|*.g03|*.g04|*.g05|*.g06|*.g07|*.g08";
            Dictionary<string, int> dic = new Dictionary<string, int>();
            var thread = new Thread(() =>
                        foreach (var dir in Ftp.ftpconn.GetDirectories("/" + dirname))
                            if (!dir.Name.Equals(".") && !dir.Name.Equals(".."))
                                dic.Add(dir.Name, 0);

                        Ftp.ftpconn.SetCurrentDirectory("/" + dirname);
                        foreach (var files in Ftp.ftpconn.GetFiles())
                            string[] f = filters.Split('|');
                            if (f.Contains("*"+files.Extension) && !files.Extension.Equals(""))
                                dic.Add(files.Name, 1);
                    catch (Exception ex)


            return dic;