Skip to content

Instantly share code, notes, and snippets.

@ps1dr3x
Last active December 3, 2022 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ps1dr3x/192f5b3a27688e7bb86d34eef401995c to your computer and use it in GitHub Desktop.
Save ps1dr3x/192f5b3a27688e7bb86d34eef401995c to your computer and use it in GitHub Desktop.
Send and receive a file using python's HTTPServer to receive and curl or powershell to send
from os import curdir
from os.path import join as pjoin
from http.server import BaseHTTPRequestHandler, HTTPServer
class StoreHandler(BaseHTTPRequestHandler):
store_path = pjoin(curdir, 'file')
def do_POST(self):
if self.path == '/':
length = self.headers['content-length']
data = self.rfile.read(int(length))
with open(self.store_path, 'wb') as fh:
fh.write(data)
self.send_response(200)
server = HTTPServer(('', 8080), StoreHandler)
server.serve_forever()
curl -v <uri> --data-binary @<file_path>
Invoke-RestMethod -Uri <url> -Method Post -InFile <file_path> -UseDefaultCredentials
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment