-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·30 lines (27 loc) · 920 Bytes
/
server.py
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
#!/usr/bin/env python3
import os
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self, path):
base_path="/mnt/data2/"
fp = os.path.join(base_path, path)
if not os.path.exists(fp):
return self.write("Not found")
if os.path.isdir(fp):
items = os.listdir(fp)
items2 = []
for item in items:
if os.path.isdir(os.path.join(fp,item)):
item = item+"/"
items2.append(item)
self.render("dir.html",items=items2, title=path)
return
self.set_header("Content-Type", "binary/octet-stream")
self.write(open(fp,"rb").read())
application = tornado.web.Application([
(r"/(.*)", MainHandler),
], debug=True)
if __name__ == "__main__":
application.listen(1234)
tornado.ioloop.IOLoop.instance().start()