2017-05-24 32 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() 
[] 
相關問題