tom*_*sen 4 python ftp python-3.x
我想上传一个ASCII文件.这曾经在Python 2中工作:
ftp = ftplib.FTP('ftp.domain.com')
ftp.login('domain.com',password)
ftp.cwd('subdirectory')
ftp.storlines('STOR ' + 'file.htm', open('file.htm','r'))
ftp.close()
Run Code Online (Sandbox Code Playgroud)
但是,在Python 3中它返回此错误:
File "/usr/local/lib/python3.3/ftplib.py", line 497, in storlines
if buf[-1] in B_CRLF: buf = buf[:-1]
TypeError: Type str doesn't support the buffer API
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我阅读了文档:http: //docs.python.org/3/library/ftplib.html#ftplib.FTP.storlines
"使用readline()方法从文件对象文件(以二进制模式打开)读取行直到EOF,以提供要存储的数据."
所以我只需要以二进制模式打开:
ftp.storlines('STOR ' + 'file.htm', open('file.htm','rb'))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2921 次 |
| 最近记录: |