php socket连接python进行文件打包
php socket连接python进行文件打包 [代码片段(42行)]
import SocketServer import os import time class MyTCPHandler(SocketServer.BaseRequestHandler): """ The RequestHandler class for our server. It is instantiated once per connection to the server, and must override the handle() method to implement communication to the client. """ def handle(self): # self.request is the TCP socket connected to the client self.data = self.request.recv(1024).strip() basedir = "C:\\package" os.chdir( basedir ) print "%s wrote:" % self.client_address[0] print self.data if os.path.isdir(self.data)==True: source = self.data target = self.data+'.zip' zip_command = "C:\\\\WinRAR\\\\rar.exe a %s %s"%(target,source) print zip_command if os.system(zip_command) == 0: print'ok success zip' else: print'FAILED' # just send back the same data, but upper-cased self.request.send(self.data.upper()) if __name__ == "__main__": HOST, PORT = "www.putclub.com", 11111 # Create the server, binding to host on port 11111 server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler) # Activate the server; this will keep running until you # interrupt the program with Ctrl-C server.serve_forever() //该片段来自于http://outofmemory.cn
- 上一篇:php 计算一个文件夹的大小
- 下一篇:php获取一个变量的名字的方法
精彩图集
精彩文章