Decoding response!

This commit is contained in:
DESKTOP-DPA61F8\Benedek 2021-04-25 18:29:28 +02:00
parent 0765ae191d
commit 9bc3f14cd9

View File

@ -40,6 +40,7 @@ def loadPrivateKey(passphrase: str) -> RsaKey:
return rsaKey return rsaKey
def loadAddress() -> str: def loadAddress() -> str:
with open(CONFIG_LOCATION) as json_file: with open(CONFIG_LOCATION) as json_file:
data = json.load(json_file) data = json.load(json_file)
@ -121,32 +122,32 @@ while True:
if separatedCommand[0] == 'LOUT' and len(separatedCommand) == 1: if separatedCommand[0] == 'LOUT' and len(separatedCommand) == 1:
network.sendMessage(command.encode('UTF-8')) network.sendMessage(command.encode('UTF-8'))
print(network.recieveMessage()) print(network.recieveMessage().decode('UTF-8'))
continue continue
if separatedCommand[0] == 'MKD' and len(separatedCommand) == 2: if separatedCommand[0] == 'MKD' and len(separatedCommand) == 2:
network.sendMessage(command.encode('UTF-8')) network.sendMessage(command.encode('UTF-8'))
print(network.recieveMessage()) print(network.recieveMessage().decode('UTF-8'))
continue continue
if separatedCommand[0] == 'RMD' and len(separatedCommand) == 2: if separatedCommand[0] == 'RMD' and len(separatedCommand) == 2:
network.sendMessage(command.encode('UTF-8')) network.sendMessage(command.encode('UTF-8'))
print(network.recieveMessage()) print(network.recieveMessage().decode('UTF-8'))
continue continue
if separatedCommand[0] == 'GWD' and len(separatedCommand) == 1: if separatedCommand[0] == 'GWD' and len(separatedCommand) == 1:
network.sendMessage(command.encode('UTF-8')) network.sendMessage(command.encode('UTF-8'))
print(network.recieveMessage()) print(network.recieveMessage().decode('UTF-8'))
continue continue
if separatedCommand[0] == 'CWD' and len(separatedCommand) == 2: if separatedCommand[0] == 'CWD' and len(separatedCommand) == 2:
network.sendMessage(command.encode('UTF-8')) network.sendMessage(command.encode('UTF-8'))
print(network.recieveMessage()) print(network.recieveMessage().decode('UTF-8'))
continue continue
if separatedCommand[0] == 'LST' and len(separatedCommand) == 1: if separatedCommand[0] == 'LST' and len(separatedCommand) == 1:
network.sendMessage(command.encode('UTF-8')) network.sendMessage(command.encode('UTF-8'))
print(network.recieveMessage()) print(network.recieveMessage().decode('UTF-8'))
continue continue
if separatedCommand[0] == 'UPL' and len(separatedCommand) == 2: if separatedCommand[0] == 'UPL' and len(separatedCommand) == 2:
@ -158,8 +159,8 @@ while True:
network.sendMessage(file.readlines()) network.sendMessage(file.readlines())
network.sendMessage('EOF'.encode('UTF-8')) network.sendMessage('EOF'.encode('UTF-8'))
response = network.recieveMessage() response = network.recieveMessage().decode('UTF-8')
print(response.decode()) print(response)
else: else:
print('Invalid argument for file upload: ' + separatedCommand[1]) print('Invalid argument for file upload: ' + separatedCommand[1])
@ -169,18 +170,18 @@ while True:
dnlFilename = separatedCommand[1].split(os.path.sep)[-1] dnlFilename = separatedCommand[1].split(os.path.sep)[-1]
cmd = 'DNL ' + dnlFilename cmd = 'DNL ' + dnlFilename
network.sendMessage(cmd.encode('UTF-8')) network.sendMessage(cmd.encode('UTF-8'))
file = network.recieveMessage() file = network.recieveMessage().decode('UTF-8')
response = network.recieveMessage() response = network.recieveMessage().decode('UTF-8')
if response == 'OK': if response == 'OK':
with open(DOWNLOAD_LOCATION + dnlFilename, "wb+") as file: with open(DOWNLOAD_LOCATION + dnlFilename, "wb+") as file:
file.writelines(file) file.writelines(file)
else: else:
print(response.decode()) print(response)
continue continue
printCommand() printCommand()
except Exception as e: except Exception as e:
print('Error: '+str(e)) print('Error: ' + str(e))