IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    The easiest way to build a http/ftp server with Python

    bear发表于 2022-12-01 16:30:08
    love 0

    Build a HTTP Server

    # Python2
    python -m SimpleHTTPServer port
    
    # Python 3
    python -m http.server port

    Build a FTP Server

    pip install pyftpdlib
    
    python -m pyftpdlib -p 21    # notice: it's ftpd, not ftp
    
    # if you want a username and password
    python -m pyftpdlib -u USERNAME -P PASSWORD

    A powershell script could run in Windows

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    Set-Location -Path D:\Download
    Start-Process -NoNewWindow python --version
    python -m pyftpdlib -p 21 -u USERNAME -P PASSWORD
    Read-Host -Prompt "Press Enter to exit"

    Advanced Usage

    from pyftpdlib.handlers import FTPHandler
    from pyftpdlib.servers import FTPServer
    from pyftpdlib.authorizers import DummyAuthorizer
    
    
    authorizer = DummyAuthorizer()
    authorizer.add_user('python', '123456', 'F:\\Working~Study', perm='elradfmwM')
    handler = FTPHandler
    handler.authorizer = authorizer
    
    
    server = FTPServer(('0.0.0.0', 8888), handler)
    server.serve_forever()

    Reference
    https://blog.51cto.com/phyger/5182139



沪ICP备19023445号-2号
友情链接