2017-05-24 30 views
0

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.是否有可能使用pysftp模块的一些内容删除目录?

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:失败

Can any one suggest me a way to solve this problem?

回答

0
+0

我已经试过了。 rmdir完全适用于空目录,但它在具有某些内容的目录上失败。 –

+0

您coud在DIR先删除每一个对象,althought它不是最好的解决办法,因为你的目录可能包括其他目录,在它 –

+0

有一个方法> con.execute(“室射频/根/备份/数据”)<@Stavros AVRAMIDIS –

0

我必须找到出路找到。在pysftp连接对象中有一个名为'execute'的方法。我们可以使用这种方法在远程服务器上执行命令。

con.execute('rm -rf /root/backup/data') 
con.listdir() 
[] 
相关问题