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