中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Python ftp client 處理含有中文的文件名

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
# -*- coding:utf-8 -*-
'''
ftplib庫(kù)的讀寫(xiě)操作
 
文件名中含有中文的特殊處理:
收到的為utf-8格式的字符串,在保存時(shí)需要使用unicode編碼的文件名寫(xiě)入本地文件系統(tǒng)。
測(cè)試環(huán)境:
Server: File Zilla Server 0.9.50 
Client OS: Win7
 
'''
import ftplib
from ftplib import FTP
ftp = ftplib.FTP( )
ftp.connect(host='localhost',port = 21,timeout=5)     # connect to host, default port
ftp.login(user='honglei',passwd='111111' )
 
#names =[]
#def mycall(line):
    #a = [item for item in line.split(" ") if item!=" "]
    #name = a[-1]#.decode('utf-8')
    #size = a[-5] 
    #names.append(name)
#ftp.retrlines('LIST',callback=mycall)           # list directory contents
filename = '\xe8\xbf\x99\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87.txt' #從使用LIST獲取到的
ftp.retrbinary('RETR '+ filename, open(filename.decode('utf-8'), 'wb').write)
 
filename = u"本地待上傳的中文文件.txt"
try:
    ftp.storbinary('STOR '+ filename.encode('utf-8'), open(filename, 'rb'))
except ftplib.error_perm as e:
    pass

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:iOS實(shí)現(xiàn)旋轉(zhuǎn)

下一篇:使用單例模式實(shí)現(xiàn)的HttpClient工具類(lèi)