Skip to content

Commit d0635d3

Browse files
update
1 parent 3cdc1d2 commit d0635d3

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

client.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
import socket
22

3-
connip = "192.168.0.101"
3+
connip = "192.168.0.102"
44
connport = 4000
55

66
c = socket.socket()
77
c.connect((connip, connport))
8-
c.settimeout(20)
8+
c.settimeout(4)
99

1010
print("connected")
1111
welcome = c.recv(1024)
1212
print(welcome.decode())
1313
while True:
1414
sender = input("fileshell> ")
15-
#maybe we can put a if here and if its download we can put this in download mode
1615
if(sender == "download"):
1716
choose = input("Name the file you want to download: ")
1817
newname = input("What name do you want to save it as? ")
18+
#check if file exists
19+
c.send("query".encode())
20+
c.send(choose.encode())
21+
check = c.recv(1024)
22+
check = check.decode()
23+
if(check == "Does not"):
24+
print("The file does not exist")
25+
continue
1926
c.send(sender.encode())
2027
c.send(choose.encode())
21-
#test = c.recv(1024).decode()
22-
#if(test == "no file"):
23-
# print("Error: the file does not exist")
24-
# continue
25-
newfile = open(newname, "wb")
2628
print("File exists! Downloading file...")
29+
newfile = open(newname, "wb")
2730
content = c.recv(1024)
2831
while(content):
2932
try:
3033
newfile.write(content)
3134
content = c.recv(1024)
3235
except socket.timeout:
3336
newfile.close()
34-
print("Done downloading")
3537
break
3638
continue
3739
except ValueError:

server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
else:
4141
cool = "no file"
4242
sock.send(cool.encode())
43+
elif(filecommand.decode() == "query"):
44+
checkfile = sock.recv(1024).decode()
45+
if(os.path.exists(serverpath + "/" + checkfile)):
46+
sock.send("Does".encode())
47+
else:
48+
sock.send("Does not".encode())
4349
elif(filecommand.decode() == "closeserver"):
4450
s.close()
4551
quit()

0 commit comments

Comments
 (0)