webserver - How to get a directory listing in python on a web browser? -
i have web server running, listening on port 7000. when request through browser i.e. 127.0.0.1:7000/ need contents of directory listed, way command python -m simplehttpserver
on terminal responds. how do using "os" module?
socket import * import os serversocket = socket(af_inet, sock_stream) #create socket #prepare server socket serverport = 7000 serversocket.bind(('',serverport)) serversocket.listen(1) while true: print 'ready serve . . .' connectionsocket, addr = serversocket.accept() #create socket client try: message =connectionsocket.recv(1024) #receive message client print message filename = message.split()[1] f = open(filename[1:]) outputdata =f.read() #send contents of requested file client in range(0, len(outputdata)): connectionsocket.send(outputdata[i]) connectionsocket.close() print 'file received' except ioerror: connectionsocket.send('\n404 file not found\n') connectionsocket.close() serversocket.close()
Comments
Post a Comment