I am creating a backup script using pysftp module. I am able to upload and download files. When i am trying to Delete a directory with some contents i got an exception.
This is what i tried
con = pysftp.Connection('192.168.0.40',username='root',password='clado123')
con.chdir('/root/backup')
con.pwd
con.listdir()
['data', 'test']
data - directory is not empty.
test - directory is empty.
con.rmdir('test')
con.listdir()
['data']
con.rmdir('data')
OSError: Failure
Can any one suggest me a way to solve this problem?
I have find out a way. There is method called 'execute' in the pysftp connection object. We can execute commands on remote server using this method.
con.execute('rm -rf /root/backup/data')
con.listdir()
[]