public static IEnumerable <FtpListItem> GetFileListingRecursive(this FtpClient client, string startPath, FtpListOption options) { Policy retrier = Policy .Handle <Exception>() .WaitAndRetry(new[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(15) }); if (options.HasFlag(FtpListOption.Recursive)) { throw new ArgumentException("Do not use recursive option when doing a recursive listing.", "options"); } var foldersToGet = new Stack <string>(); foldersToGet.Push(startPath); IEnumerable <FtpListItem> res = new FtpListItem[0]; do { var path = foldersToGet.Pop(); var files = retrier.Execute(() => { var result = client.GetListing(path, options); return(result); }); foreach (var d in files.Where(x => x.Type == FtpFileSystemObjectType.Directory)) { foldersToGet.Push(d.FullName); } res = res.Concat(files.Where(x => x.Type != FtpFileSystemObjectType.Directory).ToList()); } while (foldersToGet.Count > 0); return(res); }