#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import signal
from threading import Thread
if sys.version_info.major == 2:
    from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
else:
    from http.server import HTTPServer, BaseHTTPRequestHandler

# to upload
# curl -T  <filename> <base_url>

class PUTHandler(BaseHTTPRequestHandler):
    def do_PUT(self):
        print("----- SOMETHING WAS PUT!! ------")
        print(self.headers)
        length = int(self.headers['Content-Length'])
        content = self.rfile.read(length)
        self.send_response(200)
        self.end_headers()
        open(os.getcwd() + self.path,'wb').write(content)

def run_on(port):
    print("Starting a server on port %i" % port)
    server_address = ('0.0.0.0',port)
    httpd = HTTPServer(server_address, PUTHandler)
    httpd.serve_forever()

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print('Port number to listen on as parameter 1')
        sys.exit(1)
    ports = [int(arg) for arg in sys.argv[1:]]
    for port_number in ports:
    	server = Thread(target=run_on, args=[port_number])
        server.daemon = True # Do not make us wait for you to exit
        server.start()
    signal.pause() # Wait for interrupt signal, e.g. KeyboardInterrupt

#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import signal
from threading import Thread
if sys.version_info.major == 2:
    from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
else:
    from http.server import HTTPServer, BaseHTTPRequestHandler

# to upload
# curl -T  <filename> <base_url>

class PUTHandler(BaseHTTPRequestHandler):
    def do_PUT(self):
        print("----- SOMETHING WAS PUT!! ------")
        print(self.headers)
        length = int(self.headers['Content-Length'])
        content = self.rfile.read(length)
        self.send_response(200)
        self.end_headers()
        open(os.getcwd() + self.path,'wb').write(content)

def run_on(port):
    print("Starting a server on port %i" % port)
    server_address = ('0.0.0.0',port)
    httpd = HTTPServer(server_address, PUTHandler)
    httpd.serve_forever()

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print('Port number to listen on as parameter 1')
        sys.exit(1)
    ports = [int(arg) for arg in sys.argv[1:]]
    for port_number in ports:
        server = Thread(target=run_on, args=[port_number])
        server.daemon = True # Do not make us wait for you to exit
        server.start()
    signal.pause() # Wait for interrupt signal, e.g. KeyboardInterrupt

Update http_put_server.py