How to List complete route

Mar 7, 2014 at 12:28 PM
Hi everybody,

When i try to use GetListing() to return a List<String>, the method dont return a right list of items, for example, if i have

/folder1/folder2/file1.txt
/folder1/folder2/file2.txt

/folder1/file1.txt
/folder1/file2.txt

...

The function, every time it changed from directory to file, the List turns 0.

How can i get a complete List with all the directories and files?

Here is an example but don't works fine...
public static List<String> GetListing(String host, String usuario, String password, String subdirectorio)
    {

        String Lelemento = "";
        List<String> ruta = new List<string>();

        using (FtpClient conn = new FtpClient())
        {
            conn.Host = host; // "localhost";
            conn.Credentials = new NetworkCredential(usuario, password);//("ftptest", "ftptest");


            foreach (FtpListItem item in conn.GetListing(conn.GetWorkingDirectory() + "/" + subdirectorio, FtpListOption.Modify | FtpListOption.Size))
            {
                if (item.Type == FtpFileSystemObjectType.Directory)
                {
                        Console.WriteLine("[Carpeta] " + item.Name);

                        ruta = GetListing(host, usuario, password, subdirectorio + "/" + item.Name);
                        Lelemento = "/" + item.Name;
                        //ruta.Add(subdirectorio + Lelemento);


                }

                if (item.Type == FtpFileSystemObjectType.File)
                {
                        Console.WriteLine("[Fichero] " + subdirectorio + "/" + item.Name);
                        Lelemento = "/" + item.Name;
                        ruta.Add(subdirectorio + Lelemento);

                }

            }


            // same example except automatically dereference symbolic links.
            // see the DereferenceLink() example for more details about resolving links.
            foreach (FtpListItem item in conn.GetListing(conn.GetWorkingDirectory(),
                FtpListOption.Modify | FtpListOption.Size | FtpListOption.DerefLinks))
            {

                switch (item.Type)
                {
                    case FtpFileSystemObjectType.Directory:
                        break;
                    case FtpFileSystemObjectType.File:
                        break;
                    case FtpFileSystemObjectType.Link:
                        if (item.LinkObject != null)
                        {
                            // switch (item.LinkObject.Type)...
                        }
                        break;
                }
            }


        }
        return ruta;

    }
Best regards.