[Twisted-Python] Ftp client

Michele Petrazzo michele.petrazzo at unipex.it
Wed Aug 3 10:53:34 EDT 2005


Andrew Bennetts wrote:

>>Is it possible to "translate" my very short and simple code to twisted 
>>ftpclint?
> 
> Probably.  If you need to send non-standard commands, you can do that with
> ftpclient.queueStringCommand("BLAH blah blah").
> 
> 

<-cut->

> 
> The right way is to re-use the existing FTPClient logic as much as possible,
> rather than reimplementing it.
> 
> What specific problems are you having with twisted.protocols.ftp.FTPClient?
> 

I change the ftpclient example with this code:

def run():
  # Create the client
  creator = ClientCreator(reactor, FTPClient, user, passwd, 0)
  creator.connectTCP('192.168.1.1', 4559).addCallback(connectionMade)
  reactor.run()

def connectionMade(ftpClient):
  # Get the current working directory
  ftpClient.pwd().addCallbacks(success, fail)


One problem is that if the user has no password, I receive an error [1] 
(if I try to connect with a simple ftp client, when I connect to the 
server, if it see that I have no password, it connect me without 
password request), however if the user _has_ password, the client 
connect correctly.

Second:
if the user _has_ password, so I can connect, I want to send "LIST 
status" command, if I use:

ftpClient.queueStringCommand("LIST").addCallbacks(success, fail)

I receive [2], and if I use:

fileList = FTPFileListProtocol()
d = ftpClient.list(' status ', fileList)
d.addCallbacks(showFiles, fail, callbackArgs=(fileList,))

I receive [3]



Returned data:

[1]
Failed.  Error was:
[Failure instance: Traceback (failure with no frames): 
twisted.protocols.ftp.ConnectionLost: ('FTP connection lost', 
<twisted.python.failure.Failure twisted.protocols.ftp.CommandFailed>)


[2]
Success!  Got response:
---
257 "/" is the current directory.
---

Failed.  Error was:
[Failure instance: Traceback (failure with no frames): 
twisted.protocols.ftp.CommandFailed: ['425 Cannot build data connection: 
Connection refused.']


[3]

Success!  Got response:
---
257 "/" is the current directory.
---
Failed.  Error was:
[Failure instance: Traceback (failure with no frames): <type 'tuple'>: 
(<twisted.python.failure.Failure <type 'tuple'>>, 0)
]


> -Andrew.
> 

Thanks,
Michele




More information about the Twisted-Python mailing list