This commit is contained in:
15
py/.vscode/launch.json
vendored
Normal file
15
py/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
// 使用 IntelliSense 了解相关属性。
|
||||
// 悬停以查看现有属性的描述。
|
||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: 当前文件",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
6
py/.vscode/settings.json
vendored
Normal file
6
py/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"python.linting.pylintEnabled": false,
|
||||
"python.linting.pep8Enabled": true,
|
||||
"python.linting.enabled": true,
|
||||
"python.pythonPath": "/usr/local/bin/python3.7"
|
||||
}
|
||||
26
py/TcpDownload.py
Normal file
26
py/TcpDownload.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import socketserver
|
||||
|
||||
|
||||
class TCPHandler(socketserver.StreamRequestHandler):
|
||||
|
||||
BASE_PATH = "/Users/aria/temp/tcp/"
|
||||
|
||||
def handle(self):
|
||||
data = self.request.recv(1024).strip()
|
||||
file_name = data.decode("utf-8")
|
||||
print("file_name: %s" % file_name)
|
||||
print("{} wrote:".format(self.client_address[0]))
|
||||
with open(self.BASE_PATH + file_name, "rb") as f:
|
||||
b = f.read(1024)
|
||||
if b:
|
||||
self.wfile.write(b)
|
||||
else:
|
||||
print("发送成功")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
HOST, PORT = "localhost", 9999
|
||||
|
||||
with socketserver.TCPServer((HOST, PORT), TCPHandler) as server:
|
||||
server.serve_forever()
|
||||
@@ -15,7 +15,8 @@ def downloader(filename):
|
||||
data = request.values.get('key')
|
||||
print(data)
|
||||
dirpath = '/Users/aria/dev/ftp'
|
||||
return send_from_directory(dirpath, filename, as_attachment=True) # as_attachment=True 一定要写,不然会变成打开,而不是下载
|
||||
# as_attachment=True 一定要写,不然会变成打开,而不是下载
|
||||
return send_from_directory(dirpath, filename, as_attachment=True)
|
||||
|
||||
|
||||
@app.route("/download1", methods=['POST', 'GET'])
|
||||
@@ -27,7 +28,9 @@ def downloader1():
|
||||
data = request.values.get('key')
|
||||
print(data)
|
||||
dirpath = 'D:/test'
|
||||
return send_from_directory(dirpath, filename, as_attachment=True) # as_attachment=True 一定要写,不然会变成打开,而不是下载
|
||||
# as_attachment=True 一定要写,不然会变成打开,而不是下载
|
||||
return send_from_directory(dirpath, filename, as_attachment=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', debug=True) # 需要关闭防火墙
|
||||
|
||||
Reference in New Issue
Block a user