用Python快速搭建http服务器和FTP服务器的步骤

实验如下:

机器ip: 192.168.0.51

搭建http服务器步骤:


#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服务器步骤:

需要安装 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


假设我们需要共享目录/tmp目录作为FTP登陆目录,建一个有认证且可写的 FTP 服务器,用户名为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服务器的端口号为2121.



开另外一个会话登陆并验证ftp服务器:

#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这边对应的日志如下:


[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服务器搭建完毕。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2286646/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15498/viewspace-2286646/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值