File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 1
1
import socket
2
2
3
- connip = "192.168.0.101 "
3
+ connip = "192.168.0.102 "
4
4
connport = 4000
5
5
6
6
c = socket .socket ()
7
7
c .connect ((connip , connport ))
8
- c .settimeout (20 )
8
+ c .settimeout (4 )
9
9
10
10
print ("connected" )
11
11
welcome = c .recv (1024 )
12
12
print (welcome .decode ())
13
13
while True :
14
14
sender = input ("fileshell> " )
15
- #maybe we can put a if here and if its download we can put this in download mode
16
15
if (sender == "download" ):
17
16
choose = input ("Name the file you want to download: " )
18
17
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
19
26
c .send (sender .encode ())
20
27
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" )
26
28
print ("File exists! Downloading file..." )
29
+ newfile = open (newname , "wb" )
27
30
content = c .recv (1024 )
28
31
while (content ):
29
32
try :
30
33
newfile .write (content )
31
34
content = c .recv (1024 )
32
35
except socket .timeout :
33
36
newfile .close ()
34
- print ("Done downloading" )
35
37
break
36
38
continue
37
39
except ValueError :
Original file line number Diff line number Diff line change 40
40
else :
41
41
cool = "no file"
42
42
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 ())
43
49
elif (filecommand .decode () == "closeserver" ):
44
50
s .close ()
45
51
quit ()
You can’t perform that action at this time.
0 commit comments