python - python3, ftplib storlines error -
i want upload ascii file. used work in 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()
however, in python 3 returns error:
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 buffer api
what doing wrong?
i read documentation: http://docs.python.org/3/library/ftplib.html#ftplib.ftp.storlines
"lines read until eof file object file (opened in binary mode) using readline() method provide data stored."
so had open in binary mode:
ftp.storlines('stor ' + 'file.htm', open('file.htm','rb'))
Comments
Post a Comment