Created
October 6, 2023 10:43
-
-
Save GoldraK/8f5144ead3e988462dd480fb2b0aa64f to your computer and use it in GitHub Desktop.
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
import socket | |
def send_file(filename, host, port): | |
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
client_socket.connect((host, port)) | |
with open(filename, "rb") as file: | |
while True: | |
chunk = file.read(2048) # 2KB chunk size | |
if not chunk: | |
break | |
client_socket.send(chunk) | |
print("File sent successfully.") | |
client_socket.close() | |
if __name__ == "__main__": | |
host = "127.0.0.1" # Server IP address | |
port = 12345 # Port to connect to | |
filename = "file_to_send.txt" # Replace with the actual file path | |
send_file(filename, host, port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment