0

I would like to download files from an SFTP Server using the package pysftp. The script should also check if the file already exists in the local path. If yes, this file should be ignored and not overwritten. The following code downloads the file but overwrites the existing files each time:

import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
sftp = pysftp.Connection('XXX.XXX.XXX.XXX', username='user', password='pwd', cnopts=cnopts)
sftp.get_d(remotedir='/upload/dir', localdir='data/dir')

Can somebody help?

THX Lazloo

Lazloo Xp
  • 858
  • 1
  • 11
  • 36
  • Does this answer your question? [How do I check whether a file exists without exceptions?](https://stackoverflow.com/questions/82831/how-do-i-check-whether-a-file-exists-without-exceptions) – jjsantoso Mar 18 '20 at 15:04
  • Thanks for the suggestion, unfortunately, the scope is beyond just checking if a file already exists. It is about avoiding overwriting files using pysftp – Lazloo Xp Mar 18 '20 at 15:13

0 Answers0