利用SimpleHttpServer+urllib传文件
1、服务器
利用SimpleHTTPServer,命令行运行
python -m SimpleHTTPServer 8989
2、客户端
利用urllib等,方法有3个
import urllib print "downloading with urllib" url = 'http://192.168.1.123/test/demo.zip' print "downloading with urllib" urllib.urlretrieve(url, "demo.zip")
import urllib2 print "downloading with urllib2" url = 'http://192.168.1.123/test/demo.zip' f = urllib2.urlopen(url) data = f.read() with open("demo2.zip", "wb") as code: code.write(data)
import requests print "downloading with requests" url = 'http://192.168.1.123/test/demo.zip' r = requests.get(url) with open("demo3.zip", "wb") as code: code.write(r.content)