[Twisted-Python] ftp client question

I have this code: creator = ClientCreator(reactor, FTPClient, self._user, self._passwd, self._passive, fail=self._Fail) cre = creator.connectTCP(self._host, self._port) cre.addCallback(self._ConnectionMade) cre.addErrback(self._Fail) I see that I can add a deferred on an connection error, that receive also the commands error ("wrong user", etc..), but is there a solution for add a callback for "user logged in" (code 230)? I find one, only that is very bad, so I'm asking if someone has already wrote this code in a more "twisted manner" Thanks Michele

On Sat, 2006-07-01 at 18:06 +0200, Michele Petrazzo wrote:
I have this code:
creator = ClientCreator(reactor, FTPClient, self._user, self._passwd, self._passive, fail=self._Fail) cre = creator.connectTCP(self._host, self._port) cre.addCallback(self._ConnectionMade) cre.addErrback(self._Fail)
I see that I can add a deferred on an connection error, that receive also the commands error ("wrong user", etc..), but is there a solution for add a callback for "user logged in" (code 230)?
As far as I can see, _ConnectionMade is fired only when the login was successful (Code 230), no? Isn't that all you need?

Thomas Jacob wrote:
On Sat, 2006-07-01 at 18:06 +0200, Michele Petrazzo wrote:
I have this code:
creator = ClientCreator(reactor, FTPClient, self._user, self._passwd, self._passive, fail=self._Fail) cre = creator.connectTCP(self._host, self._port) cre.addCallback(self._ConnectionMade) cre.addErrback(self._Fail)
I see that I can add a deferred on an connection error, that receive also the commands error ("wrong user", etc..), but is there a solution for add a callback for "user logged in" (code 230)?
As far as I can see, _ConnectionMade is fired only when the login was successful (Code 230), no?
Not on my linux-box: def conn(): creator = ClientCreator(reactor, FTPClient, self._user, self._passwd, self._passive) cre = creator.connectTCP(self._host, self._port) cre.addCallback(self._ConnectionMade) cre.addErrback(self._Fail) def _ConnectionMade(self, ftpClient): print "_ConnectionMade" def _Fail(self, response): print response.getTraceback() michele:~$ python hylapex.py _ConnectionMade Traceback (most recent call last): Failure: twisted.protocols.ftp.CommandFailed: ["500 'PASS ': Syntax error, expecting password."] May be that my server isn't a "real" server, but an "hylafax" server that act like a ftp server?
Isn't that all you need?
I need a function called after the "queueLogin" successfully called and ended. Something like this bad hack: www.unipex.it/vario/myftp.py that I use: def conn(): creator = ClientCreator(reactor, FClient, self._user, self._passwd, self._passive, self._loggedin) cre = creator.connectTCP(self._host, self._port) cre.addCallback(self._ConnectionMade) cre.addErrback(self._Fail) def _loggedin(self, res): print res self._loggedin = 1 def _ConnectionMade(self, ftpClient): print "_ConnectionMade" self._connected = 1 def _Fail(self, response): print response.getTraceback() michele:~$ python hylapex.py _ConnectionMade ['230 User michele logged in.'] Michele

May be that my server isn't a "real" server, but an "hylafax" server that act like a ftp server?
I guess that's the problem. Looking at your myftp.py and your email, maybe the hylafax-ftp-server responds with a 230 after the USER command, even though a password is still required, thereby violating the FTP protocol: http://cr.yp.to/ftp/user.html ?

Thomas Jacob wrote:
May be that my server isn't a "real" server, but an "hylafax" server that act like a ftp server?
I guess that's the problem. Looking at your myftp.py and your email, maybe the hylafax-ftp-server responds with a 230 after the USER command, even though a password is still required, thereby violating the FTP protocol:
This isn't true: at "def cancelPasswordIfNotNeeded(response):", I add: "print response" and: _ConnectionMade ['331 Password required for michele.'] # send the password ['230 User michele logged in.'] So hylafax (ftp server) work well, like specification! You can read also the old "user+230" issue: twistedmatrix.com/trac/ticket/1130
?
For me and my project, my patch work, but isn't so beautiful to see, and I have to control if all work well every time that I update twisted. (due to the rewrite of some methods) Another thing if that if the server work like specific (like seem), twisted lack of that useful function! Thanks, Michele
participants (2)
-
Michele Petrazzo
-
Thomas Jacob