Skip to content

Instantly share code, notes, and snippets.

@Michcioperz
Created January 11, 2016 15:49
Show Gist options
  • Save Michcioperz/cbf0bba2654ff3899b9c to your computer and use it in GitHub Desktop.
Save Michcioperz/cbf0bba2654ff3899b9c to your computer and use it in GitHub Desktop.
quick file sharing over network solution based on lighttpd
#!/usr/bin/env python3
import argparse, tempfile, subprocess, os
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--port", type=int, default=5004)
args = parser.parse_args()
conffd, conffile = tempfile.mkstemp(suffix="hostmenow")
os.close(conffd) # because it's idiotic
with open(conffile, "w") as f:
f.write("""
server.document-root = "%s"
server.port = %i
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".js" => "text/javascript",
".jpg" => "image/jpeg",
".png" => "image/png"
)
dir-listing.activate = "enable"
""" % (os.getcwd(), args.port))
assert subprocess.call(["lighttpd", "-t", "-f", conffile]) == 0
subprocess.call(["lighttpd", "-D", "-f", conffile])
os.remove(conffile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment