/// <summary>
        /// Executes all of the commands in the pipeline list
        /// </summary>
        /// <returns>An array of FtpCommandResult objects. The order of the objects relates
        /// to the order that commands were executed.</returns>
        public FtpCommandResult[] EndExecute()
        {
            FtpCommandResult[] results = new FtpCommandResult[this.ExecuteList.Count];
            int reslocation            = 0;

            this.LockControlConnection();

            try {
                MemoryStream cmdstream = new MemoryStream();
                byte[]       buf       = new byte[this.SendBufferSize];
                int          read      = 0;

                WriteLineToLogStream("*** BEGIN PIPELINE");

                for (int i = 0; i < this.ExecuteList.Count; i++)
                {
                    if (this.ExecuteList[i] != null)
                    {
                        //this.WriteLine(this.ExecuteList[i]);
                        string traceout;
                        byte[] cmd;
                        string cmdStr = string.Format("{0}\r\n", this.ExecuteList[i]);
                        if (_caps != FtpCapability.EMPTY && this.HasCapability(FtpCapability.UTF8))
                        {
                            cmd = Encoding.UTF8.GetBytes(cmdStr);
                        }
                        else
                        {
                            cmd = Encoding.Default.GetBytes(cmdStr);
                        }


                        if (this.ExecuteList[i].ToUpper().StartsWith("PASS"))
                        {
                            traceout = "< PASS [omitted for security]";
                        }
                        else
                        {
                            traceout = string.Format("< {0}", this.ExecuteList[i].Trim('\n').Trim('\r'));
                        }

                        WriteLineToLogStream(traceout);
                        cmdstream.Write(cmd, 0, cmd.Length);

                        // check the pipeline limits
                        if (this.MaxPipelineExecute > 0 && ((i + 1) % this.MaxPipelineExecute) == 0)
                        {
                            WriteLineToLogStream("*** PIPELINE LIMIT REACHED AT " + this.MaxPipelineExecute);

                            // write the commands in blocks to the socket
                            cmdstream.Seek(0, SeekOrigin.Begin);
                            while ((read = cmdstream.Read(buf, 0, buf.Length)) > 0)
                            {
                                this.Write(buf, 0, read);
                            }
                            cmdstream.Dispose();
                            cmdstream = new MemoryStream();

                            for (; reslocation <= i; reslocation++)
                            {
                                this.ReadResponse();
                                results[reslocation] = new FtpCommandResult(this);
                            }

                            WriteLineToLogStream("*** RESUMING PIPELINE EXECUTION AT " + i + "/" + this.ExecuteList.Count);
                        }
                    }
                }

                // write the commands in blocks to the control socket
                cmdstream.Seek(0, SeekOrigin.Begin);
                while ((read = cmdstream.Read(buf, 0, buf.Length)) > 0)
                {
                    this.Write(buf, 0, read);
                }
                cmdstream.Dispose();

                // go ahead and read the rest of the responses if there are any
                for (; reslocation < this.ExecuteList.Count; reslocation++)
                {
                    this.ReadResponse();
                    results[reslocation] = new FtpCommandResult(this);
                }

                WriteLineToLogStream("*** END PIPELINE");
            }
            finally {
                this.UnlockControlConnection();
                this.ExecuteList.Clear();
                this.PipelineInProgress = false;
            }

            return(results);
        }
        /// <summary>
        /// Executes all of the commands in the pipeline list
        /// </summary>
        /// <returns>An array of FtpCommandResult objects. The order of the objects relates
        /// to the order that commands were executed.</returns>
        public FtpCommandResult[] EndExecute() {
            FtpCommandResult[] results = new FtpCommandResult[this.ExecuteList.Count];
            int reslocation = 0;

            this.LockControlConnection();

            try {
                MemoryStream cmdstream = new MemoryStream();
                byte[] buf = new byte[this.SendBufferSize];
                int read = 0;

                WriteLineToLogStream("*** BEGIN PIPELINE");

                for (int i = 0; i < this.ExecuteList.Count; i++) {
                    if (this.ExecuteList[i] != null) {
                        //this.WriteLine(this.ExecuteList[i]);
                        string traceout;
                        byte[] cmd;
                        string cmdStr = string.Format("{0}\r\n", this.ExecuteList[i]);
                        if (_caps != FtpCapability.EMPTY && this.HasCapability(FtpCapability.UTF8)) {
                            cmd = Encoding.UTF8.GetBytes(cmdStr);
                        }
                        else {
                            cmd = Encoding.Default.GetBytes(cmdStr);
                        }


                        if (this.ExecuteList[i].ToUpper().StartsWith("PASS")) {
                            traceout = "< PASS [omitted for security]";
                        }
                        else {
                            traceout = string.Format("< {0}", this.ExecuteList[i].Trim('\n').Trim('\r'));
                        }

                        WriteLineToLogStream(traceout);
                        cmdstream.Write(cmd, 0, cmd.Length);

                        // check the pipeline limits
                        if (this.MaxPipelineExecute > 0 && ((i + 1) % this.MaxPipelineExecute) == 0) {
                            WriteLineToLogStream("*** PIPELINE LIMIT REACHED AT " + this.MaxPipelineExecute);

                            // write the commands in blocks to the socket
                            cmdstream.Seek(0, SeekOrigin.Begin);
                            while ((read = cmdstream.Read(buf, 0, buf.Length)) > 0)
                                this.Write(buf, 0, read);
                            cmdstream.Dispose();
                            cmdstream = new MemoryStream();

                            for (; reslocation <= i; reslocation++) {
                                this.ReadResponse();
                                results[reslocation] = new FtpCommandResult(this);
                            }

                            WriteLineToLogStream("*** RESUMING PIPELINE EXECUTION AT " + i + "/" + this.ExecuteList.Count);
                        }
                    }
                }

                // write the commands in blocks to the control socket
                cmdstream.Seek(0, SeekOrigin.Begin);
                while ((read = cmdstream.Read(buf, 0, buf.Length)) > 0)
                    this.Write(buf, 0, read);
                cmdstream.Dispose();

                // go ahead and read the rest of the responses if there are any
                for (; reslocation < this.ExecuteList.Count; reslocation++) {
                    this.ReadResponse();
                    results[reslocation] = new FtpCommandResult(this);
                }

                WriteLineToLogStream("*** END PIPELINE");
            }
            finally {
                this.UnlockControlConnection();
                this.ExecuteList.Clear();
                this.PipelineInProgress = false;
            }

            return results;
        }