File Share
Live on this serverPassword protected directory listing with resumable downloads.
Shares a folder with friends: they log in with their browser, browse through the files and download them.
Listing renders a page for every folder, and basic authentication asks for a user name and a password -
here friend and secret.
Range support lets browsers and download managers pause and resume the download of a large file. Put the
files to share into a files folder next to the program.
To run it, create a console app (dotnet new console), add GenHTTP (dotnet add package GenHTTP.Full), replace Program.cs with the code below and start it with dotnet run - it answers at http://localhost:8080/.
using GenHTTP.Engine.Internal;
using GenHTTP.Modules.Authentication;
using GenHTTP.Modules.DirectoryBrowsing;
using GenHTTP.Modules.IO;
using GenHTTP.Modules.Practices;
var auth = BasicAuthentication.Create()
.Add("friend", "secret");
var app = Listing.From(ResourceTree.FromDirectory("./files"))
.AddRangeSupport()
.Authentication(auth);
await Host.Create()
.Handler(app)
.Defaults()
.RunAsync();
Try it
Send the requests to the sample running on this server - change the path, headers or body as you like, or copy them as curl commands.
Browse the files
Log in as "friend" with password "secret".
Download the first 100 bytes of a file
206 Partial Content
curl -i -H 'Authorization: Basic ZnJpZW5kOnNlY3JldA==' -H 'Range: bytes=0-99' 'https://genhttp.org/demo/file-share/README.md'