Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mimetypes
- from network import Network
- def is_binary(file):
- try:
- with open(file, 'r') as f:
- f.read()
- return False
- except UnicodeDecodeError:
- f.close()
- return True
- network = Network()
- command = input("Type in a command: ")
- if command == "send file: ":
- file = command.split(": ")[1]
- network.send("file start")
- print("run")
- datadict = dict()
- datadict["name"] = file
- datadict["encoding"] = mimetypes.guess_type(file)[1]
- datadict["binary"] = is_binary(file)
- block_count = 0
- blocks = list()
- with open(file, 'r' + 'b' if datadict["binary"] else '') as f:
- l = f.read(2048)
- while l:
- print("done")
- block_count += 1
- blocks.append(l)
- l = f.read(2048)
- datadict["blocks"] = block_count
- print(datadict)
- for b in blocks:
- network.send(b)
- if network.receive() != 1:
- print("Error in transmitting file.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement