0

I'm making launcher application, and in downloading part I need to fill the progress, so I need to know the size of the directory I downloading. I download it file by file from an FTP-server like this:

foreach(string dir in SubDirsArray)
{
     bool has = CheckForSubdirs(dir);
     if(has){GetAndAddToArray()}
     else if(!has)
     {
         download()
         progressbar.value += (DirSize / 100) / (filesize / 100);
     }
}

its only simplified example code, not actual one btw

DirSize should be initialized before that part of the code. And in order not to repeat this code and not to slow the downloading process I've searched for the way to get size without touching subdirectories and files, but I found nothing. So is there any way to get size like that?

  • FTP uses compression/encoding which will be different for different types of files. There is also Text and Binary modes which are handled differently. – jdweng Jun 29 '20 at 13:49
  • 2
    Make a first request, setting the `FtpWebRequest.Method` to `WebRequestMethods.Ftp.ListDirectoryDetails`. Parse that list, sum the size of files and there you have your `DirSize`. – Jimi Jun 29 '20 at 14:26

0 Answers0