本篇內(nèi)容介紹了“Python快速搭建http服務(wù)器和FTP服務(wù)器的步驟”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)主要從事網(wǎng)站制作、成都網(wǎng)站設(shè)計、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)托克托,十年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108
實驗如下:
機器ip: 192.168.0.51
搭建http服務(wù)器步驟:
#python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.254.8 - - [27/Dec/2018 13:59:27] "GET / HTTP/1.1" 200 -
192.168.254.8 - - [27/Dec/2018 13:59:36] code 404, message File not found
192.168.254.8 - - [27/Dec/2018 13:59:36] "GET /favicon.ico HTTP/1.1" 404 -
訪問:
http://192.168.0.51:8000/
搭建FTP服務(wù)器步驟:
需要安裝 Pyftpdlib 模塊:
#pip install pyftpdlib
Collecting pyftpdlib
Downloading https://files.pythonhosted.org/packages/0d/64/eb0daca74956d0e6849b71c5ba99ab873ec59b888a1d7651d92fb686ee04/pyftpdlib-1.5.4.tar.gz (184kB)
100% |████████████████████████████████| 194kB 1.3MB/s
Installing collected packages: pyftpdlib
Running setup.py install for pyftpdlib ... done
Successfully installed pyftpdlib-1.5.4
假設(shè)我們需要共享目錄/tmp目錄作為FTP登陸目錄,建一個有認(rèn)證且可寫的 FTP 服務(wù)器,用戶名為dsf,密碼為123456,
命令如下:
#python -m pyftpdlib -i 192.168.0.51 -w -d /tmp/ -u dsf -P 123456
[I 2018-12-27 14:15:58] >>> starting FTP server on 192.168.0.51:2121, pid=4245 <<<
[I 2018-12-27 14:15:58] concurrency model: async
[I 2018-12-27 14:15:58] masquerade (NAT) address: None
[I 2018-12-27 14:15:58] passive ports: None
備注:FTP服務(wù)器的端口號為2121.
開另外一個會話登陸并驗證ftp服務(wù)器:
#ftp 192.168.0.51 2121
Connected to 192.168.0.51 (192.168.0.51).
220 pyftpdlib 1.5.4 ready.
Name (192.168.0.51:root): dsf
331 Username ok, send password.
Password: --此處輸入密碼123456
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
上傳個文件做一下測試:
ftp> put 0428.sh
local: 0428.sh remote: 0428.sh
227 Entering passive mode (192,168,140,51,174,34).
125 Data connection already open. Transfer starting.
226 Transfer complete.
251 bytes sent in 0.0573 secs (4.38 Kbytes/sec)
ftp>
FTP主機192.168.0.51這邊對應(yīng)的日志如下:
[I 2018-12-27 14:16:14] 192.168.140.52:53208-[] FTP session opened (connect)
[I 2018-12-27 14:16:26] 192.168.140.52:53208-[dsf] USER 'dsf' logged in.
[I 2018-12-27 14:16:41] 192.168.140.52:53208-[dsf] STOR /tmp/drop.sh completed=1 bytes=323 seconds=0.023
[I 2018-12-27 14:21:41] 192.168.140.52:53208-[dsf] Control connection timed out.
[I 2018-12-27 14:21:41] 192.168.140.52:53208-[dsf] FTP session closed (disconnect).
[I 2018-12-27 14:23:21] 192.168.140.52:55220-[] FTP session opened (connect)
[I 2018-12-27 14:23:26] 192.168.140.52:55220-[dsf] USER 'dsf' logged in.
[I 2018-12-27 14:23:55] 192.168.140.52:55220-[dsf] STOR /tmp/0428.sh completed=1 bytes=251 seconds=0.06
至此,ftp服務(wù)器搭建完畢。
“Python快速搭建http服務(wù)器和FTP服務(wù)器的步驟”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!