-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathls.py
More file actions
65 lines (49 loc) · 1.33 KB
/
ls.py
File metadata and controls
65 lines (49 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
###############################################################################
#
# Filename: mds_db.py
# Author: Christian Rodriguez and Jose R. Ortiz
#
# Description:
# List client for the DFS
#
import socket
from Packet import *
import sys
def usage():
print """Usage: python %s <server>:<port, default=8000>""" % sys.argv[0]
sys.exit(0)
def client(ip, port):
# Contacts the metadata server and ask for list of files.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Creating socket
try:
sock.connect((ip, port)) #Connecting socket
except:
print 'Could not connect to the server. Are you sure it is on and that you have the right port?'
p = Packet() #Making a packet
p.BuildListPacket() #Building packet
try:
sock.sendall(p.getEncodedPacket()) #Sending encoded packet
except:
print 'Could not send the encoded packet!'
files = sock.recv(1024) #Receiving list of files
p.DecodePacket(files) #Decoding Packet
try:
for files, size in p.getFileArray():
print files, size, ' bytes'
except:
print 'Could not read list of files.'
if __name__ == "__main__":
if len(sys.argv) < 2:
usage()
ip = None
port = None
server = sys.argv[1].split(":")
if len(server) == 1:
ip = server[0]
port = 8000
elif len(server) == 2:
ip = server[0]
port = int(server[1])
if not ip:
usage()
client(ip, port)