title: How to delete file just after finished to upload, python
body: <p>I need to remove each image after uploading it to my server
  I use paramiko to upload images:</p>
  
  <pre><code>remote_dir = "/path/on/remote/server/"
  with sftp.Server("user", "pass", "www.example.com") as server:
  for image in glob.glob("/local/path/to/*.png"):
      base = path.basename(image)
      server.upload(image, path.join(remote_dir, base))
      os.remove(image)
  </code></pre>
  
  <p>However, each image is removed, before upload function finishes its work. </p>
  
  <p>How can I run <code>os.remove(image)</code> after <code>server.upload</code> uploads an image to the server successfully? I am new to python and heard about python-callback, but don't know how to use it in this situation. </p>