Downloading all files in directory using FTP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jumbojs
    New Member
    • May 2009
    • 20

    Downloading all files in directory using FTP

    Hello,

    I am trying to download not one, but all files within a remote directory using FTP and C# and then save them to a local folder on my hard drive. How can I do this?

    thanks
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Get a list of all the files.
    Add them to a list of files to be downloaded.
    Loop through your list downloading one at a time.
    When it is done, take it off you list of 'to be downloaded'
    Next file on the list.

    It's pretty much like your downloading of a single file, but with a 'foreach loop' wrapped around it.

    Code:
    List<string> FilesToDownload = new LIst<string>();
    FilesToDownload = GetTheFtpDirectoryContentsMethod(URLasStringParameter);//Returns a List
    foreach (string YogiBear in FilesToDownload)
    {
         YourSingleFileDownloadMethod(YogiBear, LocalDestinationPath);
    }

    You probably want to do a few things like get the sizes of all the files to be downloaded and make sure there is sufficient room on the local directory. Do some checks that you can reach the source URL, that you have write permissions on the local destination and so on. Basic error handling stuff. But if you start with the stripped-down logic you can bolt on more and more armor until it's bullet proof.

    Comment

    Working...