This project is read-only.

How to Use Pipelines

If you're just wanting to enable the feature to be used in FtpClient and FtpControlConnection, the task is simple. You need to set the EnablePipelining property to true. Hopefully this is all you need but it may not be. I've seen in my testing that some servers will drop the control connection if you flood it with a lot of commands. This is where the MaxPipelineExecute property comes into play. The default value here is 20, meaning that if you have 100 commands queued, 20 of the commands will be written to the underlying socket and 20 responses will be read, then the next 20 will be executed, and so forth until the command queue is empty. The value 20 is not a magic number, it's just the number that I deemed stable in most scenarios. If you increase the value, do so knowing that it could break your control connection.

Pipelining Your Own Commands

Pipelining your own commands is not dependent on the EnablePipelining feature. The EnablePipelining property only applies to internal pipelining performed by FtpClient and FtpControlConnection. You can use the facilities for creating pipelines at your own discretion. Here's a quick example:

FtpClient cl = new FtpClient();

// initalize the pipeline

// execute commands as normal

// execute the queued commands
FtpCommandResult[] res = cl.EndExecute();

// check the result status of the commands
foreach(FtpCommandResult r in res) {
	if(!r.ResponseStatus) {
          // we have a failure

If you decide you want to cancel your pipeline in the middle of building your queue, you use the CancelPipeline() method. These methods are implemented in the FtpControlConnection class so people that are extending this class also have access to them. The above example is a quick and dirty one. One place that this feature is being used in the code is in FtpClient's GetListing() to retrieve last write times of the files in the listing when the LIST command is used.

One last thing. You don't need to worry about locking the command channel ( LockControlConnection() / UnlockControlConnection() ) because the code that handles executing the pipeline does so for you.

Last edited Aug 16, 2011 at 4:32 PM by jptrosclair, version 4


No comments yet.