I'm using the pysftp module to implement a function to put some files onto an FTP site. Following the suggestion in the cookbook for version 0.29, I opened the connection in a with statement:
with psyftp.Connection(host=SERVER, port=PORT, username=USER, password=PASS) as ftp:
(I know using all caps for parameter names is not ideal python style. Please don't judge.) Running this results in:
AttributeError: __exit__
Research on StackOverflow says this happens because the with
statement requires an object that has __enter__
and __exit__
methods. You get this error when you use with
on an object that doesn't include them, i.e., not a context manager.
Is pysftp not really a context manager, despite its claim, or is there something more subtle going on? I can program my routine without relying on the "with" statement, I'm just wondering what the deal is here.
Contextmanager is working on the current version:
SFTP = SSH File Transfer Protocol, FTP = File Transfer Protocol