Sometimes you just need a simple file server to make a document quickly accessible for a colleague, a customer, or maybe a family member. Generally people who aren’t technical don’t have the means to provide you with access to transfer files to them, heck, even technical people often don’t have easy access to tools? To boot, there are proxies, firewalls, and other hinderances that make access difficult.
I was in this situation, I needed to get a large (~1.5GB) file to a non-technical friend on a network that blocked everything except HTTP. Time was of the essence.
Finding a HTTP server that was fast and super easy to setup and above all trustworth isn’t the easiest, but I had recently written a small webapp in Golang and that was simple and succint.
Here it is in one go! (see what I did there?)
// creates file server structure fs := http.FileServer(http.Dir(".")) // exposes it until the root http path http.Handle("/", fs) // serves the files up on port 4000 http.ListenAndServe(":4000", nil)
That’s it. That will create a file server on port 4000 sharing the current directory.
I like to have my Go /bin directory in my $PATH so when I run a
go install the http-server is now accesible anyway, so sharing the contents of a folder is as easy as navigate to that folder and running
Side note about ports
I generally don’t have access to the systems that will let me expose a port to the public internet and that’s where ngrok comes in. Ngrok is a reverse proxy that easily lets you expose a local port to the web. In conjunction with this little http-server, I have ngrok configured and can simply run
ngrok http 4000 will automatically forward the file server, running on port 4000 to an ngrok url that can be accessed publicly.
Caution should be used, as you are funneling your traffic through another web host, I can’t speak to the level of their security.