赞
踩
./download_server.py test.zip
在CentOS 7.4下编写和自测,其他环境运行时请注意python需要装有flask库
#!/usr/bin/env python #coding=utf-8 import sys import os from flask import Flask, render_template, send_from_directory, make_response app = Flask(__name__) file_name = sys.argv[1] @app.route('/', methods=['GET']) def index(): down_url = "http://127.0.0.1:5000/{}".format(file_name) return '<html><body><h1>Download Server</h1><a href="{0}">{0}</a></body></html>'.format(down_url) @app.route('/'+file_name, methods=['GET']) def down(): exec_path = os.getcwd() file_path = '/'.join([exec_path,file_name]) if os.path.exists(file_path): return make_response(send_from_directory('./', file_name, as_attachment=True)) else: return '{}目录下没有找到名称为{}的文件'.format(exec_path,file_name) if __name__ == "__main__": app.run(host='0.0.0.0',port='5000', debug=False)
./download_server.py test.zip
[root@TestSystem ~]# ./download_server.py test.zip
* Serving Flask app "download_server" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
http://127.0.0.1:5000
(如果其他人需要访问,请替换为你的内网ip,端口不动)# 关闭服务器:
# 快捷键 Ctrl + C
# 启动:
[root@TestSystem ~]# ./download_server.py aaa.zip
当前目录下没有找到名称为aaa.zip的文件
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。