We have SFTP server with authentication enabled. To access the server we need to provide both the password and private key. I'm able to access the server using winscp. But not able to access using the python code.
I have tried with pysftp and paramiko modules, but no luck. When i check the paramiko module, its not considering the password if private key is passed in the connect call.
Below is my code, can you please check suggest me if there is any approach to solve this problem.
Code using paramiko
client = paramiko.client.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
pk = paramiko.RSAKey.from_private_key_file('private_key_path')
client.connect('sftp.exmple.com', username='username', port=22, password='password', pkey=pk)
client.open_sftp()
Code using pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection('sftp.exmple.com', username='usernmae', port=22, password='password', cnopts=cnopts, private_key='private_key_path') as sftp:
sftp.put('test.txt','/tmp')
sftp.close()