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

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -