資源簡(jiǎn)介
python http 客戶端 實(shí)現(xiàn)文件或者文本上傳下載
代碼片段和文件信息
#coding=utf-8??
‘‘‘‘‘?
輸入文件名,并且上傳?
‘‘‘??
import?socket??
import?time??
import?struct??
import?os??
import?logging
if?os.path.isdir(‘G:\pythontest\log‘):
???pass
else:
???os.mkdir(‘G:\pythontest\log‘)
host?=‘192.168.1.112‘?#服務(wù)器IP
port?=?8888
dir=?“G:\pythontest\data“
for?rootdirsfiles?in?os.walk(dir):??#遍歷所有文件放到list中
????for?file?in?files:
????????sock?=?socket.socket(socket.AF_INETsocket.SOCK_STREAM)??
????????sock.settimeout(1)??
????????e=0??
????????try:??
????????????sock.connect((hostport))??
????????????print?‘??????!‘??
????????except?socket.timeoute:??
????????????print?‘timeout‘e??
????????except?socket.errore:??
????????????print?‘error‘e??
????????except?e:??
????????????print?‘a(chǎn)ny‘e?????
????????print?os.path.join(rootfile)
????????F
- 上一篇:Python進(jìn)階
- 下一篇:python http 服務(wù)端客戶端
評(píng)論
共有 條評(píng)論