0
比方说,我有一个叫做lhosts
文件,它的可执行文件:如何使用`send_file()`保留文件的权限?
-rwxr-xr-x 1 kevin kevin 2.4K Apr 27 21:16 lhosts*
这里是我的代码使用Flask.send_file()
发送文件:
#!/usr/bin/env python3
from flask import Flask, send_file
app = Flask(__name__)
@app.route('/lhosts')
def lhosts():
return send_file('scripts/lhosts')
app.run(debug=True)
然而,当我试图发送文件给客户端,它不保留权限。该许可变得无法执行:
> wget 'http://127.0.0.1:5000/lhosts' --preserve-permissions
--2016-04-27 22:27:39-- http://127.0.0.1:5000/lhosts
Connecting to 127.0.0.1:5000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [application/octet-stream]
Saving to: ‘lhosts’
lhosts 100%[================================================================>] 2.33K --.-KB/s in 0s
2016-04-27 22:27:39 (76.7 MB/s) - ‘lhosts’ saved [2381/2381]
> ls -lh lhosts
-rw-r--r-- 1 kevin kevin 2.4K Apr 27 21:16 lhosts
如何保持文件可执行?
HTTP响应应该如何指示权限?当客户端在Windows上时,如果服务器位于GNU/Linux上,会发生什么情况? – 2016-04-27 14:37:23
如果你想保留权限,你可以添加代码到你的视图来压缩文件发送之前...如果接收器解压缩它,它应该有旧的权限。 – Bastian