I have a large xml file stored in a variable. I want to write it directly to an ftp using pysftp. I believe I need to use the pysftp.putfo and this needs a file like object. Here is a minimal example:
from io import StringIO
from pysftp import Connection, CnOpts
cnopts = CnOpts()
cnopts.hostkeys = None
with Connection('localhost'
,username= 'admin'
,password = 'test'
,cnopts=cnopts
) as sftp:
sftp.putfo(StringIO('xml string'))
I get the following error:
TypeError: Expected unicode or bytes, got None
What am I doing wrong? And is there maybe a simpler and better way of achieving my goal of writing a string variable to a file on an ftp?