2017-05-24 15 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

ディレクトリ内のすべてのオブジェクトを最初に削除しましたが、ディレクトリに他のディレクトリが含まれている可能性があるため、最善の解決策ではありません。 –

+0

> con.execute( 'rm -rf/root/backup/data')<@Stavrosアブラミディス –

0

私は道を見つける必要があります。 pysftp接続オブジェクトに 'execute'というメソッドがあります。このメソッドを使用して、リモートサーバー上でコマンドを実行できます。

con.execute('rm -rf /root/backup/data') 
con.listdir() 
[] 
関連する問題