title: Ensure a file is written to a computer prior to executing commands
body: <p>I am using Python 3.8's SFTP with SSH Client to write a file to a remote computer on a remote connection. However, I want to ensure that the file is written to the computer prior to executing further commands on the system. Is there a way I can ensure this? This is an API function performed on a POST request. What if I want to remove a file and rewrite the contents. (In this case, I do a delete and a write, but is there a more efficient way to do this?) Template Code is Below.</p>
  <pre><code> def APICall(SSH_client, event):
       fileContent = event['body']['content']
       if event['body']['rewrite'] == 'true':
             SSH_client.exec_command('rm fileName')
       ftp = SSH_client.open_sftp()
       file = ftp.file(&quot;fileName&quot;,&quot;a&quot;,-1)
       file.write(fileContent)
       file.flush()
       ftp.close()
       commands = [commands]
       for command in commands:
             SSH_client.exec_command(command)
  </code></pre>
  <p>If anything is unclear in my question, please do ask for further context.</p>