Created
December 13, 2025 08:42
-
-
Save Eddy-Barraud/6e2eb308a6a95b58bcb43cc85498c595 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import os | |
| import sys | |
| import socket | |
| import threading | |
| import time | |
| from pyftpdlib.authorizers import DummyAuthorizer | |
| from pyftpdlib.handlers import FTPHandler | |
| from pyftpdlib.servers import FTPServer | |
| # Auto-detect folder containing this script (for Finder double-click) | |
| directory = os.path.dirname(os.path.abspath(__file__)) | |
| authorizer = DummyAuthorizer() | |
| # Grant anonymous user full permissions including write access | |
| # Files will be created with the permissions of the user running this script | |
| authorizer.add_anonymous(directory, perm="elradfmwMT") | |
| handler = FTPHandler | |
| handler.authorizer = authorizer | |
| # Data transfer settings for streaming | |
| handler.timeout = 7200 # 2 hour timeout for control commands | |
| handler.dtp_handler.timeout = 7200 # 2 hour timeout for data transfers | |
| # Connection pool settings | |
| handler.max_cons = 100 | |
| handler.max_cons_per_ip = 100 # Allow multiple connections per IP | |
| # Enable passive mode for better streaming support | |
| handler.permit_foreign_addresses = True | |
| handler.passive_ports = range(1024, 65535) # All non-privileged ports | |
| server = FTPServer(("0.0.0.0", 2121), handler) | |
| server.max_cons = 100 | |
| print(f"FTP server running on port 2121, sharing: {directory}") | |
| print("✓ Optimized for streaming clients with keep-alive support") | |
| print("✓ 2-hour timeouts for long-running transfers") | |
| print("✓ Connection limits: 50 total, 50 per IP") | |
| print("✓ TCP keep-alive enabled (60s idle, 30s probes, 5 attempts)") | |
| print("✓ Socket buffers optimized (256KB send/recv)") | |
| print("✓ TCP_NODELAY enabled for low-latency streaming") | |
| print("Access via ftp://your-ip:2121 (anonymous)") | |
| print("\nServer started...") | |
| server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment