12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/usr/bin/env python3
- """
- pip install pyftpdlib
- """
- import argparse
- import os
- from os import path
- from pyftpdlib.handlers import FTPHandler
- from pyftpdlib.servers import FTPServer
- from pyftpdlib.authorizers import DummyAuthorizer
- handler = FTPHandler
- def init_auth(dir):
- authorizer = DummyAuthorizer()
- authorizer.add_user('admin', '123456', dir, perm='elradfmwM')
- handler.authorizer = authorizer
- if __name__ == "__main__":
- parser = argparse.ArgumentParser(description='ftp module of argparse')
- # 指定-p/--port的参数
- # 类型为int
- # help为简短地说明
- parser.add_argument(
- '-p', '--port', default=2121, type=int,
- help='ftp server port'
- )
- # 指定-H/--host
- parser.add_argument(
- '-H', '--host', default="localhost", type=str,
- help='ftp server bind host'
- )
- # 指定-d/--dir参数
- parser.add_argument(
- '-d', '--dir', default=".", type=str,
- help='ftp server user home'
- )
- args = parser.parse_args()
- dir = path.abspath(args.dir)
- print("current dir: {}", dir)
- init_auth(dir)
- server = FTPServer((args.host, args.port), handler)
- print("ftp server start at: {}:{}".format(args.host, args.port))
- server.serve_forever()
|