Home > Blockchain >  How to upload multiple files from windows folder to SFTP folder in python
How to upload multiple files from windows folder to SFTP folder in python

Time:11-18

I am trying to upload all the files in my windows folder to SFTP folder , below is my code if there is no files in csv folder , nothing should happen how to achieve this

with pysftp.Connection(host=config('SFTP_HOST'),username=config('SFTP_USERNAME'),password=config('SFTP_PASSWORD'),cnopts=cnopts) as sftp:
    localpath = r'files\csv'
    remotepath = '/2021/November'
    sftp.put(localpath,remotepath)

it throws the below error for now.

PermissionError: [Errno 13] Permission denied: 'files\csv'

CodePudding user response:

The Connection.put can upload a single file only.

To upload all files in a folder, you can use Connection.put_d. For a recursive upload, you can use Connection.put_r. Unfortunately neither works on Windows.

But it's easy to implement a portable recursive upload, see:
Python pysftp put_r does not work on Windows

  • Related