Skip to content

Commit 7b29cf5

Browse files
committed
Adding all Files.
1 parent 96ff494 commit 7b29cf5

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

client.py renamed to Session Container/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
msg = server.recv(1024)
1111
print(msg.decode('utf-8') + "\n")
1212

13-
emptyResponseCommands = ["cls"]
13+
emptyResponseCommands = ["cls", "exit"]
1414

1515
while True:
1616
cwd = os.getcwd().encode("utf-8")
@@ -23,8 +23,6 @@
2323
print("\nConnection Terminated.")
2424
break
2525
else:
26-
print(command)
27-
2826
if command == "cd .." or command == "cd..":
2927
curDir = cwd.decode("utf-8").split("\\")
3028
os.chdir("\\".join(curDir[:len(curDir)-1]))
@@ -36,6 +34,14 @@
3634
server.send(b"COMMAND EXCPETION.")
3735
elif command == "RESPOND NULL":
3836
continue
37+
elif "copy()" in command:
38+
fileName = command.split(".copy()")
39+
fileAlias = open(fileName[0], "rb")
40+
binaryData = fileAlias.read(1024)
41+
while binaryData:
42+
binaryData = fileAlias.read(1024)
43+
server.send(binaryData)
44+
server.send(b"EOF")
3945
elif command in emptyResponseCommands:
4046
server.send(b"This command is currently not supported.\n")
4147
else:

Session Container/testFile.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
random text

issues.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
-> Responses are delayed. Everything requires an additional Enter. [FIXED]
1212

1313
-> Prompt breaks for empty responses. [FIXED]
14+
15+
-> File isn't copied over connection.

server_improved.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import socket
22

3-
serversocket = socket.socket(
4-
socket.AF_INET, socket.SOCK_STREAM)
3+
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
54

65
host = socket.gethostname()
76
port = 6969
@@ -12,14 +11,15 @@
1211

1312
clientsocket, addr = serversocket.accept()
1413
clientsocket.send(b"Connection Succesful.")
15-
#print(addr)
14+
15+
customCommands = ["download()", "upload()"]
1616

1717
print("Connection Succesful.\n")
1818
print("\n\n=====CLIENT TERMINAL=====\n\n")
1919

2020
while True:
21-
2221
cwd = "NOT A DIRECTORY"
22+
2323
while cwd == "NOT A DIRECTORY":
2424
cwd = clientsocket.recv(1024).decode("utf-8")
2525

@@ -31,6 +31,17 @@
3131
break
3232
elif command == "":
3333
clientsocket.send(b"RESPOND NULL")
34+
elif "copy()" in command:
35+
fileName = command.split(".copy()")
36+
copyFile = open(fileName[0], "ab")
37+
clientsocket.send(command.encode("utf-8"))
38+
39+
while True:
40+
filePart = clientsocket.recv(1024)
41+
if filePart == b"EOF":
42+
copyFile.close()
43+
break
44+
copyFile.write(filePart)
3445
else:
3546
clientsocket.send(command.encode("utf-8"))
3647
output = clientsocket.recv(1024).decode("utf-8")

0 commit comments

Comments
 (0)