有时候需要安装一个ftp服务器,看到一堆头疼的配置,崩溃, 找到了一个好的项目,几十行代码就可以实现一个稳定的ftp服务器,本人已经稳定运行三年多了,分享一个代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#!/bin/bash cd ~ yum install python-pip make gcc python-devel git -y git clone https://github.com/giampaolo/pyftpdlib.git git clone https://github.com/giampaolo/pysendfile.git cd ~/pysendfile python setup.py install cd ~/pyftpdlib python setup.py install cd ~ mkdir -p /ftp cat > /bin/pyftpd.py <<EOF #!/usr/bin/env python from pyftpdlib.handlers import FTPHandler from pyftpdlib.servers import ThreadedFTPServer from pyftpdlib.authorizers import DummyAuthorizer def main(): authorizer = DummyAuthorizer() authorizer.add_user('username', 'password', '/data/share/ftp', perm='elradfmwM') handler = FTPHandler # handler.masquerade_address = '151.25.42.11' # handler.passive_ports = range(60000, 65535) handler.authorizer = authorizer server = ThreadedFTPServer(('', 21021), handler) server.serve_forever() if __name__ == "__main__": main() EOF chmod +x /bin/pyftpd.py nohup /bin/pyftpd.py & |