python3, ftplib storlines error
ftp, python, python-3.x
Solution
I read the documentation: http://docs.python.org/3/library/ftplib.html#ftplib.FTP.storlines
"Lines are read until EOF from the file object file (opened in binary mode) using its readline() method to provide the data to be stored."
So I just had to open in binary mode:
ftp.storlines('STOR ' + 'file.htm', open('file.htm','rb'))
Problem
I want to upload an ASCII file. This used to 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 it returns this 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 the buffer API ``` What am I doing wrong?