如何删除owncloud中垃圾桶中的文件?
How to delete file in trash in owncloud?
我正在使用 Python。
我删除我的文件。
它们出现在 trash.I 不知道如何将它们从回收站中删除。
import owncloud
oc = owncloud.Client('ip')
oc.login('account', 'password')
p=oc.list('/')
for i in p:
oc.delete(i.path) # and than they appear in trash
目前 ownCloud 中的垃圾桶应用程序没有官方 API,因此它没有集成到 ownCloud 的 python 库中。然而,有一些 hacky 方法 可以实现您的需要。文件进入垃圾箱后,您可以使用应用程序的 ajax API 来:
从回收站中删除所有文件
如果您根本不关心垃圾箱中的内容,只想删除它们:
curl 'https://<owncloud-URL>/index.php/apps/files_trashbin/ajax/delete.php' \
-H 'OCS-APIREQUEST: true' \
-H 'Cookie: <session-token>' \
--data 'allfiles=true&dir=/'
列出并有选择地删除您想要的文件:
您可以请求其中的文件列表:
curl 'https://<owncloud-URL>/index.php/apps/files_trashbin/ajax/list.php?dir=/' \
-H 'OCS-APIREQUEST: true' \
-H 'Cookie: <session-token>'
请注意 url 上的 dir
查询参数可以与您用来列出删除 p=oc.list('/')
中所有文件的参数相同。
响应正文将如下所示:
{
"data": {
"permissions": 0,
"directory": "\/",
"files": [
{
"id": 0,
"parentId": null,
"mtime": 1505373301000,
"name": "ownCloud Manual.pdf",
"permissions": 1,
"mimetype": "application\/octet-stream",
"size": 5111899,
"type": "file",
"etag": 1505373301000,
"extraData": ".\/ownCloud Manual.pdf"
}
]
},
"status": "success"
}
然后您可以根据对象的名称和 mtimes 创建需要删除的对象 (files
) 的列表:
curl 'https://<owncloud-URL>/index.php/apps/files_trashbin/ajax/delete.php' \
-H 'OCS-APIREQUEST: true' \
-H 'Cookie: <session-token>' \
--data 'files=["<file1>.d<mtime1>","<file2>.d<mtime2>"]&dir=/'
最后说明:请求中的<mtimeX>
是请求列表时文件的属性"mtime": 1505373301000
并删除3个尾随零.还要注意通过将 2 部分与 .d
.
连接来构建名称
希望对您有所帮助!
感谢口水!
我从回收站中删除文件。
import requests
userID = 'aaa'
userPassword = 'bbbbbbb'
with requests.Session() as s:
response = s.get('http://'+userID+':'+userPassword+'@<owncloud-URL>/index.php/apps/files/?dir=/&fileid=4896' ) #change your fileid
token = response.content.split('data-requesttoken="')[1].split('"')[0]
Cookie = 'oc7b6t1tjo61='+s.cookies['oc7b6t1tjo61']+';oc_sessionPassphrase='+s.cookies['oc_sessionPassphrase']
data = {'allfiles':'true', 'dir':'/'}
headers = {'requesttoken':token, 'OCS-APIREQUEST':'true', 'Cookie':Cookie ,'Accept-Language':'zh-TW,en-US;q=0.7,en;q=0.3'}
response2 = s.post('http://<owncloud-URL>/index.php/apps/files_trashbin/ajax/delete.php',data = data, headers = headers, cookies=s.cookies)
print response2.content
我正在使用 Python。 我删除我的文件。 它们出现在 trash.I 不知道如何将它们从回收站中删除。
import owncloud
oc = owncloud.Client('ip')
oc.login('account', 'password')
p=oc.list('/')
for i in p:
oc.delete(i.path) # and than they appear in trash
目前 ownCloud 中的垃圾桶应用程序没有官方 API,因此它没有集成到 ownCloud 的 python 库中。然而,有一些 hacky 方法 可以实现您的需要。文件进入垃圾箱后,您可以使用应用程序的 ajax API 来:
从回收站中删除所有文件
如果您根本不关心垃圾箱中的内容,只想删除它们:
curl 'https://<owncloud-URL>/index.php/apps/files_trashbin/ajax/delete.php' \
-H 'OCS-APIREQUEST: true' \
-H 'Cookie: <session-token>' \
--data 'allfiles=true&dir=/'
列出并有选择地删除您想要的文件:
您可以请求其中的文件列表:
curl 'https://<owncloud-URL>/index.php/apps/files_trashbin/ajax/list.php?dir=/' \
-H 'OCS-APIREQUEST: true' \
-H 'Cookie: <session-token>'
请注意 url 上的 dir
查询参数可以与您用来列出删除 p=oc.list('/')
中所有文件的参数相同。
响应正文将如下所示:
{
"data": {
"permissions": 0,
"directory": "\/",
"files": [
{
"id": 0,
"parentId": null,
"mtime": 1505373301000,
"name": "ownCloud Manual.pdf",
"permissions": 1,
"mimetype": "application\/octet-stream",
"size": 5111899,
"type": "file",
"etag": 1505373301000,
"extraData": ".\/ownCloud Manual.pdf"
}
]
},
"status": "success"
}
然后您可以根据对象的名称和 mtimes 创建需要删除的对象 (files
) 的列表:
curl 'https://<owncloud-URL>/index.php/apps/files_trashbin/ajax/delete.php' \
-H 'OCS-APIREQUEST: true' \
-H 'Cookie: <session-token>' \
--data 'files=["<file1>.d<mtime1>","<file2>.d<mtime2>"]&dir=/'
最后说明:请求中的<mtimeX>
是请求列表时文件的属性"mtime": 1505373301000
并删除3个尾随零.还要注意通过将 2 部分与 .d
.
希望对您有所帮助!
感谢口水! 我从回收站中删除文件。
import requests
userID = 'aaa'
userPassword = 'bbbbbbb'
with requests.Session() as s:
response = s.get('http://'+userID+':'+userPassword+'@<owncloud-URL>/index.php/apps/files/?dir=/&fileid=4896' ) #change your fileid
token = response.content.split('data-requesttoken="')[1].split('"')[0]
Cookie = 'oc7b6t1tjo61='+s.cookies['oc7b6t1tjo61']+';oc_sessionPassphrase='+s.cookies['oc_sessionPassphrase']
data = {'allfiles':'true', 'dir':'/'}
headers = {'requesttoken':token, 'OCS-APIREQUEST':'true', 'Cookie':Cookie ,'Accept-Language':'zh-TW,en-US;q=0.7,en;q=0.3'}
response2 = s.post('http://<owncloud-URL>/index.php/apps/files_trashbin/ajax/delete.php',data = data, headers = headers, cookies=s.cookies)
print response2.content