wget#
wget获取指定ip路由下的全部文件-r:递归--no-parent:无父目录--accept:接收文件,支持通配符--reject:拒绝文件,支持通配符-P:指定下载路径
</>
shell
1wget -r --no-parent --accept "*.zip*" --reject "*.html" ip:port -P ./download/Http文件服务器#
- python3 http server模块快速启动
python3 -m http.server 8000 --directory /path/
</>
console
1Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
优点:快速
缺点:不能直观看到本地ip
- python3 代码
</>
python
1import socket
2import sys
3import http.server
4import socketserver
5import traceback
6
7class Handler(http.server.SimpleHTTPRequestHandler):
8 def __init__(self, *args, **kwargs):
9 super().__init__(*args, directory=target, **kwargs)
10
11 def end_headers(self):
12 self.send_header('Connection', 'close')
13 super().end_headers()
14
15def get_local_ip() -> str:
16 try:
17 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
18 s.connect(("8.8.8.8", 80))
19 local_ip = s.getsockname()[0]
20 s.close()
21 return local_ip
22 except Exception as e:
23 raise Exception(f"无法获取IP: {str(e)}\n请检查网络环境")
24
25if __name__ == '__main__':
26 local_ip = get_local_ip()
27 target = ''
28 try:
29 target = sys.argv[1]
30 except:
31 target = "."
32
33 with socketserver.ThreadingTCPServer(("", 0), Handler) as httpd:
34 port = httpd.server_address[1]
35 print(f"Serving HTTP on http://{local_ip}:{port}/")
36 try:
37 httpd.serve_forever()
38 except:
39 print(traceback.format_exc())
40 finally:
41 httpd.server_close()
42 print('exit.')</>
shell
1python3 autofileserver.py /path/优点:快速、直观看到ip:port