title: How to sync only the changed files from the remote directory using pysftp?
body: <p>I am using pysftp library's <code>get_r</code> function (<a href="https://pysftp.readthedocs.io/en/release_0.2.9/pysftp.html#pysftp.Connection.get_r" rel="noreferrer">https://pysftp.readthedocs.io/en/release_0.2.9/pysftp.html#pysftp.Connection.get_r</a>) to get a local copy of a directory structure from sftp server.</p>
  
  <p>Is that the correct approach for a situation when the contents of the remote directory have changed and I would like to get only the files that changed since the last time the script was run?</p>
  
  <p>The script should be able to sync the remote directory recursively and mirror the state of the remote directory - f.e. with a parameter controlling if the local outdated files (those that are no longer present on the remote server) should be removed, and any changes to the existing files and new files should be fetched.</p>
  
  <p><a href="https://gist.github.com/krzysztof-slowinski/59efeef7f9d00b002eed7e0e6636b084" rel="noreferrer">My current approach is here.</a></p>
  
  <p>Example usage:</p>
  
  <pre><code>from sftp_sync import sync_dir
  
  sync_dir('/remote/path/', '/local/path/')
  </code></pre>