In my file manager, I need to offer the capability of downloading files. I need to be able to select both individual files but also directories. This could be an example:
/www/index.html
/www/images/
/www/styles.css
If I select those 3 items (2 files and 1 folder), I need to add them all to a ZIP archive. I already have an working example, where I utilize DownloadFolder() and DownloadFile(). However, it goes like this:
- Download each file to disk
- If there are any folders, recursively look through them and download those files to their respective folders (automatically done)
- Call
System.IO.Compression.ZipFile.CreateFromDirectory()
to ZIP the downloaded files to a ZIP archive - Delete the downloaded files from before
- Stream the ZIP file back using
new FileStream(zipFile, FileMode.Open, FileAccess.Read, FileShare.None, 4096, FileOptions.DeleteOnClose)
so the ZIP file gets deleted afterwards
This is quite bad, because I need to first download the files, add them to an archive, delete the files I just downloaded, stream the archive to the user, and then finally delete the archive to clean up. What would be better:
- Tell FluentFTP which files to stream
- Create a ZIP archive ON DISK
- Add each file and directory recursively to the archive
- Stream the archive back and delete the file afterwards
By doing this, I should be able to make very, very large files (100+ GB if that's a case), and all I would have to care about, is temporary storage until the archive has been deleted.
I wasn't able to find any information on how to do this, so something tells me, I need to call the GetListing() method with the FtpListOption.Recursive
flag, then create each directory "manually", and finally call the Download() method, which returns a stream.
Are there any better ways, though?