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?

Adil B
  • 14,635
  • 11
  • 60
  • 78
  • 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. – Rup Oct 01 '18 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: https://stackoverflow.com/questions/29128205/debug-option-for-python-sftp-script-like-ftp-setdebug1-to-log-messages – matyas Oct 01 '18 at 10:34

1 Answers1

1

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

Lie Ryan
  • 62,238
  • 13
  • 100
  • 144
  • 1
    If that's the case, then `put_r` might not help either, as I believe [it's broken the same way `get_r` is](https://stackoverflow.com/q/50118919/850848) (not working on Windows, what OP needs). – Martin Prikryl Oct 01 '18 at 10:39
  • 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. – somanath mishra Oct 01 '18 at 20:02