[ftputil] Setting a passive/active connection during the same connection
Stefan Schwarzer
sschwarzer at sschwarzer.net
Sun Mar 23 23:09:21 CET 2008
Hi Marco,
On 2008-03-23 20:37, Marco Buccini wrote:
> Stefan Schwarzer ha scritto:
>> On 2008-03-23 17:48, Marco Buccini wrote:
>> Note that the session_factory can by any callable, not
>> necessarily a class. Thus, you could use
>>
>> def factory(host, user, pass, port):
>> session = ftplib.FTP(host, user, pass, port)
>> session.set_pasv(True)
>> return session
>>
>> host = ftputil.FTPHost(host, user, pass, port,
>> session_factory=factory)
>>
>> which is a bit shorter than using a class as the session
>> factory.
>
> I've already used this method, but I've found a little (big) problem.
> Imagine you want to switch to active from passive or vice versa during
> an established connection. You've to instanciate another FTPConnection
> object, haven't you? So the previous connection is lost, and you've to
> create a new connection. It' s not a good way .. :(
Is this an actual use case? If yes, could you describe the
concrete application in more detail? Is it actually bad for
performance (or otherwise) to open a new connection?
> For example, if you use linux and open a ftp command line client, you
> can set passive/active at whatever time you want.
Again, I wonder whether this (changing at any time) is
needed. I think, also in command line clients you _usually_
change active/passive mode not more than once per
connection.
> What do you suggest me?
If you actually have an application which (according to
measurements!) benefits from switching the mode on an
established FTPHost instance please tell me. :-) You can
compare the approaches by accessing FTPHost._session
directly; just for tests, not production code, this should
be ok.
I can _imagine_ a use case for changing the mode of the
session after establishing the connection: You try some
commands, and if they fail, you retry after switching from
active to passive (or vice versa). However, if you deal
with a certain remote host, you will probably need this
switching only one time and reuse the knowledge of active/
passive mode for multiple connections. So the loss of
reopening a single connection for dealing with - in the
end - several connections to a server for some time
probably isn't critical, only a bit inconvenient.
> Thank you for your helping me.
You're welcome (as always). :-)
Stefan
More information about the ftputil
mailing list