Compare commits

...

5 Commits

Author SHA1 Message Date
f65db31c12 Config
All checks were successful
continuous-integration/drone/push Build is passing
2021-04-30 11:00:28 +02:00
e7c4945ae9 OK
All checks were successful
continuous-integration/drone/push Build is passing
2021-04-29 19:17:48 +02:00
94fcda4c2c RMF
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:25:52 +02:00
c40e59ceb9 OK
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:06:30 +02:00
57af60ee07 Server address
All checks were successful
continuous-integration/drone/push Build is passing
2021-04-26 23:35:00 +02:00
2 changed files with 25 additions and 9 deletions

View File

@ -11,6 +11,8 @@ from netwrapper import NetWrapper
ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
DOWNLOAD_LOCATION = ABSOLUTE_PATH + os.path.sep + 'download' + os.path.sep
CONFIG_LOCATION = ABSOLUTE_PATH + os.path.sep + 'config' + os.path.sep + 'config.txt'
PASSPHRASE = ''
SERVER_ADDRESS = ''
LOGGED_IN = False
@ -54,6 +56,7 @@ def printCommand():
' Get current directory -> GWD \n' +
' Change current directory -> CWD <path> \n' +
' List content of current directory -> LST \n' +
' Remove file from current directory -> RMF <filename> \n' +
' Upload file to current directory -> UPL <filename> \n' +
' Download file from current directory -> DNL <filename> \n' +
' Login -> LIN <username> <password> \n' +
@ -67,7 +70,7 @@ def printCommandsWihtoutLogin():
try:
opts, args = getopt.getopt(sys.argv[1:], 'hp:')
opts, args = getopt.getopt(sys.argv[1:], 'hp:s:')
except getopt.GetoptError:
print('Error: Unknown option detected.')
sys.exit(1)
@ -76,10 +79,13 @@ for opt, arg in opts:
if opt in '-p':
PASSPHRASE = arg
if opt in '-s':
SERVER_ADDRESS = arg
if PASSPHRASE == '':
print('Key required to start client!')
print('Usage:')
print(' client.py -p <passphrase>')
print(' client.py -p <passphrase> -s <server_address>')
sys.exit(1)
if not os.path.isfile(CONFIG_LOCATION) or os.stat(CONFIG_LOCATION).st_size == 0:
@ -91,6 +97,8 @@ CLIENT_PRIVATE_KEY = loadPrivateKey(PASSPHRASE)
CLIENT_ADDRESS = loadAddress()
LOGGED_IN = False
network = NetWrapper(CLIENT_PRIVATE_KEY, CLIENT_ADDRESS, SERVER_PUBLIC_KEY, serverAddr=SERVER_ADDRESS)
while True:
command = input("Type a command:")
separatedCommand = command.split(" ")
@ -102,7 +110,7 @@ while True:
if not LOGGED_IN:
if separatedCommand[0] == 'LIN' and len(separatedCommand) == 3:
network = NetWrapper(CLIENT_PRIVATE_KEY, CLIENT_ADDRESS, separatedCommand[1], SERVER_PUBLIC_KEY)
network.username = separatedCommand[1]
try:
network.connectToServer(separatedCommand[2])
response = network.recieveMessage().decode('UTF-8')
@ -115,7 +123,6 @@ while True:
print("Error: "+str(e))
LOGGED_IN = False
continue
continue
else:
print('You are already logged in!')
@ -130,6 +137,7 @@ while True:
if separatedCommand[0] == 'LOUT' and len(separatedCommand) == 1:
network.sendMessage(command.encode('UTF-8'))
print(network.recieveMessage().decode('UTF-8'))
LOGGED_IN = False
continue
if separatedCommand[0] == 'MKD' and len(separatedCommand) == 2:
@ -157,13 +165,18 @@ while True:
print(network.recieveMessage().decode('UTF-8'))
continue
if separatedCommand[0] == 'RMF' and len(separatedCommand) == 2:
network.sendMessage(command.encode('UTF-8'))
print(network.recieveMessage().decode('UTF-8'))
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:
network.sendMessage(file.readlines())
network.sendMessage(file.read())
network.sendMessage('EOF'.encode('UTF-8'))
response = network.recieveMessage().decode('UTF-8')
@ -177,12 +190,15 @@ while True:
dnlFilename = separatedCommand[1].split(os.path.sep)[-1]
cmd = 'DNL ' + dnlFilename
network.sendMessage(cmd.encode('UTF-8'))
file = network.recieveMessage().decode('UTF-8')
filecontent = network.recieveMessage()
response = network.recieveMessage().decode('UTF-8')
if response == 'OK':
print(DOWNLOAD_LOCATION + dnlFilename)
if response == 'EOF':
with open(DOWNLOAD_LOCATION + dnlFilename, "wb+") as file:
file.writelines(file)
file.write(filecontent)
print('OK')
else:
print(response)

File diff suppressed because one or more lines are too long