File tree Expand file tree Collapse file tree 2 files changed +33
-15
lines changed Expand file tree Collapse file tree 2 files changed +33
-15
lines changed Original file line number Diff line number Diff line change @@ -35,10 +35,15 @@ def append_to_file(file_name, message):
35
35
fd .write (message )
36
36
37
37
38
- def list_files (directory ):
39
- temp_list = os .listdir (directory )
40
- for file in temp_list :
41
- print (file )
38
+ def list_files (server_sock , directory ):
39
+ while True :
40
+ data = server_sock .recv (1024 )
41
+ if not data :
42
+ break
43
+ temp_list = data
44
+ for item in temp_list :
45
+ print (item )
46
+
42
47
43
48
44
49
def send_file (server_sock , file_name ):
@@ -72,10 +77,15 @@ def make_socket():
72
77
# create a socket object
73
78
s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
74
79
75
- # get local machine name
76
- host = socket .gethostname ()
80
+ # get server ip
81
+ print ("Enter server IP" )
82
+ msg = input ()
83
+ host = msg
77
84
78
- port = 9999
85
+ # get server port
86
+ print ("Enter server port" )
87
+ msg = input ()
88
+ port = msg
79
89
80
90
# connection to hostname on the port.
81
91
s .connect ((host , port ))
Original file line number Diff line number Diff line change 1
1
import socket
2
2
import threading
3
+ import os
3
4
4
5
# set directory for file server
5
6
root = "Root/"
@@ -53,15 +54,22 @@ def recieve_from_server(socket):
53
54
54
55
msg = socket .recv (1024 )
55
56
if len (msg ) == 0 :
56
- socket .close ()
57
- elif msg .decode ("utf-8" ) == "close" :
58
- socket .close ()
57
+ socket .send ("error" )
58
+ elif msg == "list local" :
59
+ temp_list = list_local ("Root" )
60
+ socket .send (str (temp_list ))
59
61
else :
60
- if msg .decode ("utf-8" ) == "download" :
61
- msg = "Here is your downloaded file haha"
62
- socket .send (msg .encode ("utf-8" ))
63
- else :
64
- socket .send (msg )
62
+ socket .send ("error" )
63
+
64
+
65
+ def list_local (directory ):
66
+ temp_list = os .listdir (directory )
67
+ return temp_list
68
+
69
+
70
+ def list_global ():
71
+ for server in servers :
72
+ server .send ("list local" )
65
73
66
74
67
75
def send_file (client_sock , file_name ):
You can’t perform that action at this time.
0 commit comments