Skip to content

Instantly share code, notes, and snippets.

@sudhackar
Last active July 15, 2019 07:31
Show Gist options
  • Save sudhackar/8710f8ba97f6f5047c70b18e6130d145 to your computer and use it in GitHub Desktop.
Save sudhackar/8710f8ba97f6f5047c70b18e6130d145 to your computer and use it in GitHub Desktop.
Server to rcv files
import BaseHTTPServer
import os
# for i in `find / -type f`; do
class Multiplier(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
query = s.path.split('files')[1]
s.send_response(200)
s.send_header("Content-type", "text/plain")
s.end_headers()
s.wfile.write(query)
def do_POST(s):
query = s.path.split('files')[1]
filename = "." + query
s.send_response(200)
s.send_header("Content-type", "text/plain")
s.end_headers()
s.wfile.write(query)
length = int(s.headers.getheader('Content-Length'))
content = s.rfile.read(length)
if not os.path.exists(os.path.dirname(filename)):
try:
os.makedirs(os.path.dirname(filename))
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise
with open(filename, "w") as f:
f.write(content)
def run_while_true(
server_class=BaseHTTPServer.HTTPServer,
handler_class=Multiplier):
server_address = ('0.0.0.0', 8000)
httpd = server_class(server_address, handler_class)
while True:
httpd.handle_request()
run_while_true()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment