To set up a quick FTP server in Python, you can use the pyftpdlib library. This library allows you to easily deploy an FTP server with just a few lines of code.
First, you need to install the pyftpdlib library if you don't already have it. You can install it using pip:
bash
pip install pyftpdlib
Once you have installed the library, you can create a simple Python script to start the FTP server. The following example will start an FTP server on your local machine with anonymous access (be cautious with this, as it will allow anyone on your network to access the server):
python
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
def main():
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions and a read-only anonymous user
# WARNING: granting write permissions to anonymous users can be very dangerous!
authorizer.add_user("user", "password", "/path/to/share", perm="elradfmw")
authorizer.add_anonymous("/path/to/share", perm="elr")
# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
# Define a customized banner (string returned when client connects)
handler.banner = "Welcome to my FTP server."
# Specify a range of passive ports to be used (helpful when behind a firewall)
handler.passive_ports = range(60000, 65535)
# Instantiate FTP server class and listen to 0.0.0.0:21
address = ('0.0.0.0', 21)
server = FTPServer(address, handler)
# Set a limit for connections
server.max_cons = 256
server.max_cons_per_ip = 5
# Start FTP server
server.serve_forever()
if __name__ == "__main__":
main()
Before you run the script, make sure to:
Replace /path/to/share with the actual directory path you want to share.
Replace "user" and "password" with the desired username and password for your FTP user.
Adjust permissions as necessary. The permissions string uses the following letters: "e" change directory (CWD, CDUP commands), "l" list files (LIST, NLST, STAT, MLSD, MLST, SIZE commands), "r" retrieve file from the server (RETR command), "a" append data to an existing file (APPE command), "d" delete file or directory (DELE, RMD commands), "f" rename file or directory (RNFR, RNTO commands), "m" create directory (MKD command), "w" store a file to the server (STOR, STOU commands).
Configure the passive_ports range according to your network's firewall settings, if necessary.
When you run the script, it will start an FTP server that you can access from any FTP client on the local network. Be aware that transferring very large files (like the 7GB - 49GB files you mentioned) can take a considerable amount of time, depending on the speed of your network.
Please note that FTP is considered an insecure protocol because it transmits data in plaintext. If security is a concern, consider using SFTP or FTPS, or sharing files over a secure channel like a VPN.