Created
June 16, 2023 20:27
-
-
Save pavgup/ae1008027b24d27eecf240e3533fc31d to your computer and use it in GitHub Desktop.
using curl to send a file to a remote machine
This file contains hidden or 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
# on the remote server you want to use to send a file, you run: | |
# curl -F "file=@/log.txt" http://100.100.100.100:8000/ | |
# this will create the file log.txt in /tmp that will ideally containt he log.txt from the remote machine | |
from http.server import SimpleHTTPRequestHandler | |
import os | |
class FileUploadHandler(SimpleHTTPRequestHandler): | |
def do_POST(self): | |
content_length = int(self.headers['Content-Length']) | |
uploaded_file = self.rfile.read(content_length) | |
file_name = os.path.basename("log.txt") | |
# Provide the base directory path where the uploaded file should be stored | |
base_directory = '/tmp' | |
file_path = os.path.join(base_directory, file_name) | |
with open(file_path, 'wb') as file: | |
file.write(uploaded_file) | |
self.send_response(200) | |
self.end_headers() | |
self.wfile.write(b'File uploaded successfully') | |
if __name__ == '__main__': | |
from http.server import HTTPServer | |
server_address = ('', 8000) | |
httpd = HTTPServer(server_address, FileUploadHandler) | |
print('Serving HTTP on 0.0.0.0 port 8000...') | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment