先上代码
```
def main():
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions
authorizer.add_user('', '','d:/dd/cc', perm='elradfmwM')
# Define a read-only anonymous user
authorizer.add_anonymous('d:/dd/cc')
# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
# Define a customized banner (string returned when client connects)
handler.banner = "Welcome to Jayvic's FTP."
# Instantiate FTP server class and listen on 127.0.0.1:21
address = ('192.168.0.159', 21)
server = FTPServer(address, handler)
# set a limit for connections
server.max_cons = 256
server.max_cons_per_ip = 5
# start ftp server
server.serve_forever()
```
遇到两个问题:
1. address = ('192.168.0.159', 21) 这里面的 ip 配置成啥,就必须用对应的 ip 访问,如果设置成了 127.0.0.1 就不能用 192 的 ip 访问,反之亦然,这个怎么回事?有什么办法解决
2. 我试过在 windows 下搭建,然后在 192 网内( linux/win )访问都正常,但是在虚拟机( ip 是 10.0.0.15 )可以访问到,但是不能连接,提示错误: 501 Rejected data connection to foreign address 10.0.2.15:36606.。 这个怎么解决?
```
def main():
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions
authorizer.add_user('', '','d:/dd/cc', perm='elradfmwM')
# Define a read-only anonymous user
authorizer.add_anonymous('d:/dd/cc')
# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
# Define a customized banner (string returned when client connects)
handler.banner = "Welcome to Jayvic's FTP."
# Instantiate FTP server class and listen on 127.0.0.1:21
address = ('192.168.0.159', 21)
server = FTPServer(address, handler)
# set a limit for connections
server.max_cons = 256
server.max_cons_per_ip = 5
# start ftp server
server.serve_forever()
```
遇到两个问题:
1. address = ('192.168.0.159', 21) 这里面的 ip 配置成啥,就必须用对应的 ip 访问,如果设置成了 127.0.0.1 就不能用 192 的 ip 访问,反之亦然,这个怎么回事?有什么办法解决
2. 我试过在 windows 下搭建,然后在 192 网内( linux/win )访问都正常,但是在虚拟机( ip 是 10.0.0.15 )可以访问到,但是不能连接,提示错误: 501 Rejected data connection to foreign address 10.0.2.15:36606.。 这个怎么解决?