I would like to test code which connects to a ftp server as clients and up- and downloads files.
Is there a Python library which provides a context manager which runs a ftp server on localhost (port 2121)?
I would like the usage of this library look roughly like this:
def test_my_ftp_foo(self): with ftp_server_context(user='myuser', password='mypassword', port=2121): with ftputil.FTPHost(host='localhost', 'myuser', 'mypassword', port=2121) as host: host.makedirs('a/b') host.chrdir(...') ...
I see several ways to implement this library.
One would be to use subprocess.Popen() and run a script using pyftpdlib until
__exit__() tells the context manager to kill the ftp server.