Files
archie/tests/servers/ftp_server.py
Mario Fetka 1e4baef047 Port Archie 3.5 to Linux/CMake, add Debian packaging and CI
- Replace autoconf/make build system with CMake (installs to /opt/archie)
- Add CPack DEB packaging for Debian Trixie (non-free/net, postinst creates
  archie user, extracts DB skeleton, sets setuid bits, enables systemd units)
- Add Gitea Actions workflow building .deb + binary/source tarballs on tag push
- Add portable archie_init.py for non-Debian post-install setup
- Port all scripts to Linux: getent passwd, systemctl, tail -n +N, gzip
- Add SFTP (libssh2) and FTPS (OpenSSL) scrapers alongside anonftp
- Add Flask web frontend (archie-web.service)
- Fix filter scripts (exec cat replaces broken sed s///g)
- Update all manpages: paths, contacts, add SFTP/FTPS section
- Update etc/: enable gzip, add webindex catalog, fix localhost refs
- Remove: AIX-2/SunOS-4.1.4/SunOS-5.4 dirs, tcl7.6/, tcl-dp/, tk4.2/,
  berkdb/, old Makefile.in/pre/post fragments, build.sh, unwrap scripts
- Add .gitignore

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 23:05:12 +02:00

54 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Plain FTP test server using pyftpdlib.
Usage:
python3 ftp_server.py [--host 127.0.0.1] [--port 2121] [--root /tmp/ftp-root]
Credentials: anonymous / anonymous@
"""
import argparse
import logging
import os
import sys
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--host", default="127.0.0.1")
ap.add_argument("--port", type=int, default=2121)
ap.add_argument("--root", default="/tmp/ftp-root")
ap.add_argument("--user", default="anonymous")
ap.add_argument("--password", default="")
ap.add_argument("--passive-ports", default="60000-60100")
args = ap.parse_args()
os.makedirs(args.root, exist_ok=True)
low, high = map(int, args.passive_ports.split("-"))
authorizer = DummyAuthorizer()
authorizer.add_anonymous(args.root, perm="elr")
authorizer.add_user("testuser", "testpass", args.root, perm="elradfmw")
handler = FTPHandler
handler.authorizer = authorizer
handler.passive_ports = range(low, high + 1)
handler.banner = "Archie test FTP server"
logging.basicConfig(level=logging.INFO,
format="%(asctime)s [FTP] %(message)s")
server = FTPServer((args.host, args.port), handler)
print(f"FTP server listening on {args.host}:{args.port}, root={args.root}",
flush=True)
server.serve_forever()
if __name__ == "__main__":
main()