I am new into python and i am trying to download file/folder(s) from a SFTP server using pysftp library.
I am looking for recursive download so i am using pysftp.get_r()
method.
Below are the cases:
1) root folder contains only folders : Working as expected.
2) root folder contains folders and file: giving error stating FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:/Tools/DownloadedFromPython\\./'
Below is the code which i have written
import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys.load('C:/Users/xxx/.ssh/known_hosts')
lPath = 'C:/Tools/DownloadedFromPython'
sPath = '/'
sftp = pysftp.Connection(host='hostname', username='xxx', password='xxx', cnopts=cnopts)
if not os.path.exists(lPath):
os.makedirs(lPath)
if sftp.exists(sPath):
sftp.get_r(sPath, lPath)
print('done')