[Zope-CVS] CVS: Packages/SFTPGateway/src/sftpgateway -
connector.py:1.33
Fred L. Drake, Jr.
fred at zope.com
Mon Dec 22 11:47:43 EST 2003
Update of /cvs-repository/Packages/SFTPGateway/src/sftpgateway
In directory cvs.zope.org:/tmp/cvs-serv4230
Modified Files:
connector.py
Log Message:
- deal with "old" scanDirectory() from Twisted 1.1.1
- handle a missing FTP server better
=== Packages/SFTPGateway/src/sftpgateway/connector.py 1.32 => 1.33 ===
--- Packages/SFTPGateway/src/sftpgateway/connector.py:1.32 Mon Dec 22 11:05:05 2003
+++ Packages/SFTPGateway/src/sftpgateway/connector.py Mon Dec 22 11:47:42 2003
@@ -21,6 +21,7 @@
from twisted.conch.ssh import filetransfer
from twisted.conch.ssh.filetransfer import SFTPError
from twisted.internet import defer, protocol, reactor
+from twisted.internet.error import ConnectionRefusedError
from twisted.protocols import basic, ftp
from twisted.python import failure
@@ -64,7 +65,28 @@
return ftp.FTPClient.fail(self, error)
-class FTPConnector(filetransfer.FileTransferServer):
+
+class FileTransferServerPatch(filetransfer.FileTransferServer):
+ """Support for the 'older' flavor of the FileTransferServer
+ provided in Twisted 1.1.1.
+ """
+
+ def scanDirectory(self, directory):
+ L = []
+ while len(L) < 250:
+ try:
+ info = directory.next()
+ except StopIteration:
+ if not L:
+ raise EOFError
+ else:
+ break
+ else:
+ L.append(info)
+ return L
+
+
+class FTPConnector(FileTransferServerPatch):
def __init__(self, app, avatar):
self._app = app
@@ -85,9 +107,15 @@
self._app.debug("FTP client created")
self._client = ftpClient
return function(ftpClient, *args, **kw)
+ def errback(error):
+ error.trap(ConnectionRefusedError)
+ message = ("could not create FTP client: "
+ "connection refused")
+ self._app.debug(message)
+ raise SFTPError(filetransfer.FX_FAILURE, message)
creator = protocol.ClientCreator(reactor, MyFTPClient, self)
d = creator.connectTCP(self._host, self._port)
- d.addCallback(callback)
+ d.addCallbacks(callback, errback)
return d
else:
return function(ftpClient, *args, **kw)
More information about the Zope-CVS
mailing list