title: Append to existing file on SFTP server via pysftp
body: <p>I have one file named <code>Account.txt</code> in SFTP server, and I'm trying to appending a line to this file. This is my effort:</p>
  
  <pre><code>from io import StringIO
  from pysftp import Connection, CnOpts
  
  cnopts = CnOpts()
  cnopts.hostkeys = None
  with Connection('ftpserver.com'
                  ,username= 'username'
                  ,password = 'password'
                  ,cnopts=cnopts
                  ) as sftp:
      with sftp.cd('MY_FOLDER'):
          f = sftp.open('Account.txt', 'ab')
          data='google|33333|Phu|Wood||true|2018-09-21|2018-09-21|google'
          f.write(data+'\n')
  </code></pre>
  
  <p>When I run this above code, the file was overwritten, instead of appended.  So, How can append new line but still keep the old lines in the file?</p>
  
  <p>For example:</p>
  
  <p><strong>Account.txt file:</strong></p>
  
  <pre><code>facebook|11111|Jack|Will||true|2018-09-21|2018-09-21|facebook
  facebook|22222|Jack|Will||true|2018-09-21|2018-09-21|facebook
  </code></pre>
  
  <p>And now I want to add line "google|33333|Phu|Wood||true|2018-09-21|2018-09-21|google" to the file.
  The result I'm expecting:</p>
  
  <p><strong>Account.txt file</strong></p>
  
  <pre><code>facebook|11111|Jack|Will||true|2018-09-21|2018-09-21|facebook
  facebook|22222|Jack|Will||true|2018-09-21|2018-09-21|facebook
  google|33333|Phu|Wood||true|2018-09-21|2018-09-21|google
  </code></pre>
  
  <p>Hope you guys can understand. Leave a comment if you don't. Thank you.</p>