[Twisted-Python] RE: How do I upload files using FTPClient?

Christopher Armstrong radix at twistedmatrix.com
Tue Jan 14 22:31:22 EST 2003

On Tue, Jan 14, 2003 at 02:43:02PM -0800,  Daniel Burr wrote:
> As discussed earlier in this thread, here is a rough sketch of how I think
> a high-level interface to twisted.protocols.ftp.FTPClient should look.
> Ideally, I'd like to be able to use it like so:

>             for filePath in filePaths:
>                 fileDirectory, fileName = os.path.split(filePath)
>                 uploadDirectory = '%s/%s' % (appRoot, fileDirectory)
>                 if ftp.pwd() != (uploadDirectory):
>                     try:
>                         ftp.cd(uploadDirectory)
>                     except ftp.DirDoesNotExist:
>                         makeDirectory(uploadDirectory)
>                         ftp.cd(uploadDirectory)
>                     ftp.binary()
>                     ftp.put(fileName)
>             ftp.quit()
>             return True

This code assumes that the methods block, but they can't. Twisted is
an asynchronous framework, thus, no public interface functions (other
than reactor.run() and similar) block. I recommend implementing a
command-based FTP client on top of the asynchronous interfaces if you
actually want an interface with which you needn't worry about
asynchronous stuff. :-)

 Twisted | Christopher Armstrong: International Man of Twistery
  Radix  |          Release Manager,  Twisted Project
---------+     http://twistedmatrix.com/users/radix.twistd/

More information about the Twisted-Python mailing list