bool GetDirectoryEntries(out FtpDirectoryEntry[] entries)
        {
            if (currentFileSystemDirectory == null)
            {
                List <FtpDirectoryEntry> result = new List <FtpDirectoryEntry>();
                foreach (KeyValuePair <string, string> root in Server.RootFolders)
                {
                    result.Add(new FtpDirectoryEntry()
                    {
                        Name = root.Key,
                        Type = FtpDirectoryEntryType.Directory,
                    });
                }
                entries = result.ToArray();
                return(true);
            }

            FtpDirectoryEntry.GetEntries(currentFileSystemDirectory, utf8, out entries);
            FtpAccessEventArgs e = new FtpAccessEventArgs(this, FtpAccessType.ListDirectory, ".", currentFtpFolder, currentFileSystemDirectory, entries);

            Server.OnCheckAccess(e);
            if (e.Denied)
            {
                SendAnswer("550 Requested action not taken. Access denied.");
                entries = null;
                return(false);
            }
            entries = e.Entries;
            return(true);
        }
        /// <summary>
        /// Gets all entries at the specified folder.
        /// </summary>
        /// <param name="folder">Base folder.</param>
        /// <param name="utf8">Use utf8 encoding.</param>
        /// <param name="entries">Retrieves all entries found.</param>
        public static void GetEntries(string folder, bool utf8, out FtpDirectoryEntry[] entries)
        {
            List <FtpDirectoryEntry> list = new List <FtpDirectoryEntry>
            {
                new FtpDirectoryEntry()
                {
                    Name        = ".",
                    DateTime    = FileSystem.GetLastWriteTime(folder),
                    Permissions = 775,
                    Type        = FtpDirectoryEntryType.Directory,
                },
            };

            string[] dirs = new string[0];
            try
            {
                dirs = Directory.GetDirectories(folder);
            }
            catch
            {
            }
            foreach (string dirName in dirs)
            {
                try
                {
                    FtpDirectoryEntry entry = new FtpDirectoryEntry()
                    {
                        DateTime    = FileSystem.GetLastWriteTime(dirName),
                        Name        = Path.GetFileName(dirName),
                        Permissions = 775,
                        Type        = FtpDirectoryEntryType.Directory,
                    };
                    if (!utf8 && entry.Name.HasInvalidChars(ASCII.Strings.Printable))
                    {
                        Trace.TraceWarning("File contains non ascii chars and client does not use utf8.");
                        entry.Name = ASCII.Escape(entry.Name, '~');
                    }
                    list.Add(entry);
                }
                catch
                {
                    list.Add(new FtpDirectoryEntry()
                    {
                        Name = dirName, Type = FtpDirectoryEntryType.Directory
                    });
                }
            }

            string[] files = new string[0];
            try
            {
                files = Directory.GetFiles(folder);
            }
            catch
            {
            }
            foreach (string name in files)
            {
                FtpDirectoryEntry entry = new FtpDirectoryEntry()
                {
                    DateTime    = FileSystem.GetLastWriteTime(name),
                    Size        = FileSystem.GetSize(name),
                    Permissions = 664,
                    Name        = Path.GetFileName(name),
                    Type        = FtpDirectoryEntryType.File,
                };
                if (!utf8 && entry.Name.HasInvalidChars(ASCII.Strings.Printable))
                {
                    Trace.TraceWarning("File contains non ascii chars and client does not use utf8.");
                    entry.Name = ASCII.Escape(entry.Name, '~');
                }
                list.Add(entry);
            }

            entries = list.ToArray();
        }