Last active
December 3, 2022 20:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -v <uri> --data-binary @<file_path> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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