I'd like to upload multiple files from a Windows directory to an SFTP server using pysftp 0.2.8. I've read up the doc and it suggests to use put_d
or put_r
but both give me the following error:
OSError: Invalid path:
sftp_local_path = r'C:\Users\Swiss\some\path'
sftp_remote_path = '/FTP/LPS Data/ATC/RAND/20191019_RAND/XML'
with pysftp.Connection("xxx.xxx.xxx.xxx", username=myUsername, password=myPassword) as sftp:
with sftp.cd(sftp_remote_path):
sftp.put_r(sftp_local_path, sftp_remote_path)
for i in sftp.listdir():
lstatout=str(sftp.lstat(i)).split()[0]
if 'd' in lstatout: print (i, 'is a directory')
sftp.close()
I'd like to be able to copy all files or selected files from my local directory to the SFTP server.