somanath mishra
somanath mishra

Reputation: 25

Move files from local to remote server using sftp in python

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?

Upvotes: 1

Views: 2811

Answers (1)

Lie Ryan
Lie Ryan

Reputation: 64953

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

Upvotes: 1

Related Questions