1

I want to copy all files from a local directory to a remote directory. I used the pysftp library for that. My code below is not showing any errors, but my local files are also not being transferred to my remote server.

My code:

import pysftp
remotepath = '/home/a7user/sftp/sftp/CentralData/'
localpath = 'E:\\backup\\'
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None

with pysftp.Connection(host='xx.xxx.xx.xx',username='user',password='5fTPt00',cnopts=cnopts) as sftp:

 sftp.put_d(localpath,remotepath)
 print('Upload finished')

What am I doing incorrectly?

2
  • By the look of it there's no easy logging in pysftp. Assuming put_d is the right method (it's not recursive - that's put_r), I think your best bet is to edit your local copy of pysftp to add print statements to walktree() and put_d() to see what it's doing. It might also be worth checking you can transfer a single file using cd and put. Commented Oct 1, 2018 at 10:33
  • 1
    could you add log=1 when you create the Connection and add the output of the log to your question? with pysftp.Connection(host='xx.xxx.xx.xx',username='user',password='5fTPt00',cnopts=cnopts, log=1) as sftp: stackoverflow.com/questions/29128205/… Commented Oct 1, 2018 at 10:34

1 Answer 1

1

Chances are what you really want to use is put_r() and not put_d()?

Sign up to request clarification or add additional context in comments.

2 Comments

If that's the case, then put_r might not help either, as I believe it's broken the same way get_r is (not working on Windows, what OP needs).
Thanks @LieRyan put_r( ) worked for me and actual issue was with latest version. My version was 3.7 when i tested in 3.5 version it worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.