2018-12-06 10:54:18 337浏览
今天扣丁学堂Python培训老师给大家介绍一下关于如何用Python快速实现HTTP和FTP服务器的详解,有时你需临时搭建一个简单的WebServer,但你又不想去安装Apache、Nginx等这类功能较复杂的HTTP服务程序时。这时可以使用Python内建的SimpleHTTPServer模块快速搭建一个简单的HTTP服务器。
$ cd /Users/Mike/Docker $ python -m SimpleHTTPServer Serving HTTP on 0.0.0.0 port 8000 ...SimpleHTTPServer模块默认会在8000端口上监听一个HTTP服务,这时就可以打开浏览器输入http://IP:Port访问这个Web页面。例如类似下面的URL:
http://192.168.100.49:8000
$ python -m SimpleHTTPServer 8080
$ sudo pip install pyftpdlib
$ cd /Users/Mike/Docker $ python -m pyftpdlib [I 2018-01-02 16:24:02] >>> starting FTP server on :::2121, pid=7517 <<< [I 2018-01-02 16:24:02] concurrency model: async [I 2018-01-02 16:24:02] masquerade (NAT) address: None [I 2018-01-02 16:24:02] passive ports: None
ftp://192.168.100.49:2121
$ python -m pyftpdlib -i 192.168.100.49 -w -d /tmp/ -u mike -P 123456
$ python -m pyftpdlib --help Usage: python -m pyftpdlib [options] Start a stand alone anonymous FTP server. Options: -h, --help show this help message and exit -i ADDRESS, --interface=ADDRESS specify the interface to run on (default all interfaces) -p PORT, --port=PORT specify port number to run on (default 2121) -w, --write grants write access for logged in user (default read-only) -d FOLDER, --directory=FOLDER specify the directory to share (default current directory) -n ADDRESS, --nat-address=ADDRESS the NAT address to use for passive connections -r FROM-TO, --range=FROM-TO the range of TCP ports to use for passive connections (e.g. -r 8000-9000) -D, --debug enable DEBUG logging evel -v, --version print pyftpdlib version and exit -V, --verbose activate a more verbose logging -u USERNAME, --username=USERNAME specify username to login with (anonymous login will be disabled and password required if supplied) -P PASSWORD, --password=PASSWORD specify a password to login with (username required to be useful)
$ pip uninstall pyftpdlib
【关注微信公众号获取更多学习资料】