diff --git a/client/client.py b/client/client.py index 563a806..88ecefb 100644 --- a/client/client.py +++ b/client/client.py @@ -45,6 +45,7 @@ def loadAddress() -> str: data = json.load(json_file) return data['address'] + def printCommand(): print('\nInvalid command! Available commands:\n' + ' Create directory -> MKD \n' + @@ -120,40 +121,63 @@ while True: if separatedCommand[0] == 'LOUT' and len(separatedCommand) == 1: network.sendMessage(command.encode('UTF-8')) + print(network.recieveMessage()) continue if separatedCommand[0] == 'MKD' and len(separatedCommand) == 2: network.sendMessage(command.encode('UTF-8')) + print(network.recieveMessage()) continue if separatedCommand[0] == 'RMD' and len(separatedCommand) == 2: network.sendMessage(command.encode('UTF-8')) + print(network.recieveMessage()) continue if separatedCommand[0] == 'GWD' and len(separatedCommand) == 1: network.sendMessage(command.encode('UTF-8')) + print(network.recieveMessage()) continue if separatedCommand[0] == 'CWD' and len(separatedCommand) == 2: network.sendMessage(command.encode('UTF-8')) + print(network.recieveMessage()) continue if separatedCommand[0] == 'LST' and len(separatedCommand) == 1: network.sendMessage(command.encode('UTF-8')) + print(network.recieveMessage()) continue if separatedCommand[0] == 'UPL' and len(separatedCommand) == 2: if os.path.isfile(separatedCommand[1]): + cmd = 'UPL ' + separatedCommand[1].split(os.path.sep)[-1] + network.sendMessage(cmd.encode('UTF-8')) + with open(separatedCommand[1], "rb") as file: - print('TODO: Implement!') + network.sendMessage(file.readlines()) + + network.sendMessage('EOF'.encode('UTF-8')) + response = network.recieveMessage() + print(response.decode()) + else: print('Invalid argument for file upload: ' + separatedCommand[1]) continue if separatedCommand[0] == 'DNL' and len(separatedCommand) == 2: - dnlFilename = separatedCommand[1].rsplit(os.apth.sep, 1)[-1] - with open(DOWNLOAD_LOCATION + dnlFilename, "wb") as file: - print('TODO: Implement!') + dnlFilename = separatedCommand[1].split(os.path.sep)[-1] + cmd = 'DNL ' + dnlFilename + network.sendMessage(cmd.encode('UTF-8')) + file = network.recieveMessage() + response = network.recieveMessage() + + if response == 'OK': + with open(DOWNLOAD_LOCATION + dnlFilename, "wb+") as file: + file.writelines(file) + else: + print(response.decode()) + continue printCommand()