PS: background, can not SSH access to the machine (generally in the middle of the fortress machine Block), but the use of domain names can be accessed in the case of the use of HTTP protocol file upload.
Server-side code (accepts one end of post)
#coding =utf-8from basehttpserver import basehttprequesthandlerimport cgiclass posthandler (Basehttprequesthandler): def do_post (self): form = cgi. Fieldstorage ( fp=self.rfile, headers=self.headers, environ={' request_method ': ' POST ', ' content_type ': self.headers[' Content-type '], } ) self.send_response(a) self.end_headers () self.wfile.write (' client: %sn ' % str (self.client_address) ) self.wfile.write (' User-agent: %sn ' % str (self.headers[' User-agent ']) self.wfile.write (' Path: %sn '%self.path) self.wfile.write (' form data:n ') for field in form.keys (): field_item = form[field] filename = field_item.filename filevalue = field_item.value filesize = len (filevalue) #文件大小 (bytes) print len (Filevalue) With open (Filename.decode (' utf-8 ') + ' A ', ' WB ') as f: f.write (Filevalue) return if __name__== ' __main__ ': from basehttpserver import httpserver sever = httpserver ((' 0.0.0.0 ', 8000), PostHandler) print ' Starting server, use <ctrl-c> to stop ' sever.serve_forever ()
Client (send one end of post)
#coding =utf-8import requestsurl = ' http://xxxxxxxxxxxxxxxxxxx:8000 ' path = U '/users/test/student/py/myspider.py ' Print Pathfiles = {' file ': Open (Path, ' RB ')}r = requests.post (URL, files=files)
This article is from "someone who says I am a tech house" blog, please be sure to keep this source http://1992mrwang.blog.51cto.com/3265935/1597407
Python Post transfer File script