C# how to make it efficient to list the directories on a ftp server


I need to get the content of the file list for files with a specific format from a ftp server. I have to read through all the directories and files, to check if it is or contains the file I need, then add the file into my file list. However, there are so many directories, subdirectories, and all kinds of files in the ftp server, it will be very time-consuming to do that. does anyone know how can i make it much more time efficient?

By : 陈从坤


Since you have mentioned that the directory path varies from machine to machine, you need to have a collection of all the machines and there directory paths. You need loop through the directory paths. Unfortunately you need to loop through every files (exclude the unwanted). Below is a pseudocode-

loop for each directory paths
    loop for each files in a directory paths by excluding unwanted files types
         store the required files in a collection
    end loop
end loop
return files

You may use parallel for loop (TPL in .Net) to execute the loops faster. Refer-

This video can help you solving your question :)
By: admin