[ftputil] Setting a passive/active connection during the same connection
Marco Buccini
buccini.marco at alice.it
Sun Mar 23 20:37:07 CET 2008
Stefan Schwarzer ha scritto:
> Hello Marco,
>
> On 2008-03-23 17:48, Marco Buccini wrote:
>
>> Is there a way to set a modality passive/active during the connection
>> and not only before the connection?
>>
>> Infact with ftplib we have:
>>
>> ftp = ftplib.FTP(host,user,pass, port) #or some similar
>> ftp.set_pasv(True|False)
>>
>> Instead in ftputil we have to define a class as in the example in the
>> documentation.
>>
>
> Principally, the instantiated session object is accessible
> as FTPHost._session. Accessing it, for example via
> host._session.set_pasv(True) is not recommended: ftputil
> makes new sessions internally for child session objects
> which are used for file-like objects.
>
>
I didn't thought of this method. But I think, as you say it's not a good
method.
> So the recommended way is still to use a session factory
> callable - unless you are hundred percent sure you avoid
> use FTP file-like objects and want to risk compatibility
> problems with future ftputil versions. ;-)
>
> 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 .. :(
For example, if you use linux and open a ftp command line client, you
can set passive/active at whatever time you want.
What do you suggest me?
Thank you for your helping me.
Regards.
More information about the ftputil
mailing list