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

Andrew Bennetts andrew-twisted at puzzling.org
Tue Jan 14 19:09:23 EST 2003

On Tue, Jan 14, 2003 at 02:43:02PM -0800,  Daniel Burr wrote:
> WARNING!  Long-winded, and perhaps clueless post ahead!
> 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.
> Currently, twisted.protocols.ftp contains mostly FTP-related classes; there
> is only one module-level method, "parsePWDResponse".  I am thinking that we
> could just implement the high-level client interface as methods within the
> current twisted.protocols.ftp module.
> Ideally, I'd like to be able to use it like so:

[snip code]

> This code is pretty naive, to be sure, and not at all Twisted.  However, it
> does hopefully illustrate the way I would like to interact with an FTP
> client.  The "deploy" function could be refactored to use Deferreds pretty
> easily; the "makeDirectory" function would be similarly simple.

Indeed.  I admit it is easier to think about these things synchronously,
though :)

> As for the interface to FTPClient, I've outlined my thoughts below.  Note
> that my immediate itch only calls for "cd", "pwd", "mkdir", and "put", of
> which only "mkdir" and "put" need to be implemented.  It'd be cool, down
> the road, to implement "mget" and friends, so that my sample code above
> could be reduced even further, by removing the need to loop through the
> list of file paths and transfer files one at a time.
> My overall, grand ambition is to tie all of this together into a handy
> code deployment tool that can pull versioned code from multiple source
> control solutions, and deploy it using a variety of protocols.

Ah!  It's always nice to know what people are actually trying to do :)

> ---------------------------------------------------------------------------
> # a module level variable to which we will bind an instance of FTPClient
> theClient = None

Why do you want a global variable for this?  What's wrong with instatiating
and tracking your own FTPClient instance, and having these functions be
methods of that instance (rather than globals, as they seem to be now)?

> def append(localFile, remoteFile=localFile)
>     """
>     Append the contents of a file on the client to a file on the server
>     localFile  - string containing the name of the file on the client
>     remoteFile - string containing the name of the file on the server;
>                  defaults to the same name as the file on the client
>     """


And of course, these methods will have to return Deferreds.  Also, I don't
want FTPClient to be restricted to just plain files, as mentioned earlier,
but yeah :)

> Well, that's my brain dump for now.  Be as harsh as you like in criticizing;
> I have a thick hide, and I'm trying to learn, so don't pull any punches.
> If anyone thinks it should be entirely different, that's fantastic, and I
> want to hear about it.

That's ok... I'll have a deeper ponder on FTP with this in mind, and have
another attack at the code tonight.


More information about the Twisted-Python mailing list