The introduction of the socket is not much to say, the internet can be searched, directly say the script, to achieve the function of FTP server and client,
Server-side:
Import socketserverimport commandsimport timeclass mysockserver ( Socketserver.baserequesthandler): def handle (self): print "Got a new conn from", self.client_address while True:    CMD = SELF.REQUEST.RECV (1024x768) if not cmd:break cmd = cmd.split () if cmd[0] == "Get": print "Start transfer ..." with&nbsP;open (cmd[1], ' RB ') as f: self.request.send (F.read ()) time.sleep (0.2) self.request.send ("OOK") #这算是个标示吧. Client received this description has been passed continue cmd_result = Commands.getstatusoutput (cmd[0]) #执行客户端发地来的shell命令 self.request.send (cmd_result[1]) if __name__ == ' __main__ ': host= ' port = 52167 s = socketserver.threadingtcpserver ((host,port), MySockServer) s.serve_forever () client: Import socketimport time host = ' x.x.x.x ' #服务器的地址port = 52167addr = host,ports = socket.socket (Socket.af_inet,socket. SOCK_STREAM) s.connect (addr) while true: input = raw_input (' Please Your input: '). Strip () if len (input) ==0:continue s.send (Input) input = input.split () if Input[0]== ' Get ': print ' get file with open (input[1], ' WB ') as f: &Nbsp; f.write (S.RECV (1024x768)) Time.sleep (0.2) if s.recv (1024x768) == "OOK": print "down finsh  ..." continue   DATA = S.RECV (1024x768) print data
I've been learning Python all the time, but it's always intermittent. Can't insist. Learn for a long time to write a simple socket, this IQ let people catch nasty ah.
This article is from the Linux management blog, so be sure to keep this source http://hans925.blog.51cto.com/542170/1567973
Use a Python socket to write an FTP-like script (only the download, upload and download almost no more write)