protected override CommandStream.PipelineEntry[] BuildCommandsList(WebRequest req)
        {
            string        str3;
            string        str4;
            string        str5;
            bool          flag    = false;
            FtpWebRequest request = (FtpWebRequest)req;

            this.m_ResponseUri = request.RequestUri;
            ArrayList list = new ArrayList();

            if (request.EnableSsl && !base.UsingSecureStream)
            {
                list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("AUTH", "TLS")));
                flag = true;
            }
            if (flag)
            {
                this.m_LoginDirectory             = null;
                this.m_EstablishedServerDirectory = null;
                this.m_RequestedServerDirectory   = null;
                this.m_CurrentTypeSetting         = string.Empty;
                if (this.m_LoginState == FtpLoginState.LoggedIn)
                {
                    this.m_LoginState = FtpLoginState.LoggedInButNeedsRelogin;
                }
            }
            if (this.m_LoginState != FtpLoginState.LoggedIn)
            {
                this.Credentials      = request.Credentials.GetCredential(request.RequestUri, "basic");
                this.m_WelcomeMessage = new StringBuilder();
                this.m_ExitMessage    = new StringBuilder();
                string parameter = string.Empty;
                string password  = string.Empty;
                if (this.Credentials != null)
                {
                    parameter = this.Credentials.InternalGetDomainUserName();
                    password  = this.Credentials.InternalGetPassword();
                }
                if ((parameter.Length == 0) && (password.Length == 0))
                {
                    parameter = "anonymous";
                    password  = "******";
                }
                list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("USER", parameter)));
                list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("PASS", password), CommandStream.PipelineEntryFlags.DontLogParameter));
                if (request.EnableSsl && !base.UsingSecureStream)
                {
                    list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("PBSZ", "0")));
                    list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("PROT", "P")));
                }
                list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("OPTS", "utf8 on")));
                list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("PWD", null)));
            }
            GetPathOption normal = GetPathOption.Normal;

            if (request.MethodInfo.HasFlag(FtpMethodFlags.DoesNotTakeParameter))
            {
                normal = GetPathOption.AssumeNoFilename;
            }
            else if (request.MethodInfo.HasFlag(FtpMethodFlags.ParameterIsDirectory))
            {
                normal = GetPathOption.AssumeFilename;
            }
            GetPathInfo(normal, request.RequestUri, out str3, out str4, out str5);
            if ((str5.Length == 0) && request.MethodInfo.HasFlag(FtpMethodFlags.TakesParameter))
            {
                throw new WebException(SR.GetString("net_ftp_invalid_uri"));
            }
            if (((this.m_EstablishedServerDirectory != null) && (this.m_LoginDirectory != null)) && (this.m_EstablishedServerDirectory != this.m_LoginDirectory))
            {
                list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("CWD", this.m_LoginDirectory), CommandStream.PipelineEntryFlags.UserCommand));
                this.m_RequestedServerDirectory = this.m_LoginDirectory;
            }
            if (request.MethodInfo.HasFlag(FtpMethodFlags.MustChangeWorkingDirectoryToPath) && (str4.Length > 0))
            {
                list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("CWD", str4), CommandStream.PipelineEntryFlags.UserCommand));
                this.m_RequestedServerDirectory = str4;
            }
            if (((request.CacheProtocol != null) && (request.CacheProtocol.ProtocolStatus == CacheValidationStatus.DoNotTakeFromCache)) && (request.MethodInfo.Operation == FtpOperation.DownloadFile))
            {
                list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("MDTM", str3)));
            }
            if (!request.MethodInfo.IsCommandOnly)
            {
                if ((request.CacheProtocol == null) || (request.CacheProtocol.ProtocolStatus != CacheValidationStatus.Continue))
                {
                    string str6 = request.UseBinary ? "I" : "A";
                    if (this.m_CurrentTypeSetting != str6)
                    {
                        list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("TYPE", str6)));
                        this.m_CurrentTypeSetting = str6;
                    }
                    if (request.UsePassive)
                    {
                        string command = (base.ServerAddress.AddressFamily == AddressFamily.InterNetwork) ? "PASV" : "EPSV";
                        list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand(command, null), CommandStream.PipelineEntryFlags.CreateDataConnection));
                    }
                    else
                    {
                        string str8 = (base.ServerAddress.AddressFamily == AddressFamily.InterNetwork) ? "PORT" : "EPRT";
                        this.CreateFtpListenerSocket(request);
                        list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand(str8, this.GetPortCommandLine(request))));
                    }
                    if ((request.CacheProtocol != null) && (request.CacheProtocol.ProtocolStatus == CacheValidationStatus.CombineCachedAndServerResponse))
                    {
                        if (request.CacheProtocol.Validator.CacheEntry.StreamSize > 0L)
                        {
                            list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("REST", request.CacheProtocol.Validator.CacheEntry.StreamSize.ToString(CultureInfo.InvariantCulture))));
                        }
                    }
                    else if (request.ContentOffset > 0L)
                    {
                        list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("REST", request.ContentOffset.ToString(CultureInfo.InvariantCulture))));
                    }
                }
                else
                {
                    list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("SIZE", str3)));
                    list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("MDTM", str3)));
                }
            }
            if ((request.CacheProtocol == null) || (request.CacheProtocol.ProtocolStatus != CacheValidationStatus.Continue))
            {
                CommandStream.PipelineEntryFlags userCommand = CommandStream.PipelineEntryFlags.UserCommand;
                if (!request.MethodInfo.IsCommandOnly)
                {
                    userCommand |= CommandStream.PipelineEntryFlags.GiveDataStream;
                    if (!request.UsePassive)
                    {
                        userCommand |= CommandStream.PipelineEntryFlags.CreateDataConnection;
                    }
                }
                if (request.MethodInfo.Operation == FtpOperation.Rename)
                {
                    list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("RNFR", str4 + "/" + str5), userCommand));
                    list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("RNTO", str4 + "/" + request.RenameTo), userCommand));
                }
                else if (request.MethodInfo.HasFlag(FtpMethodFlags.DoesNotTakeParameter))
                {
                    list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand(request.Method, string.Empty), userCommand));
                }
                else if (request.MethodInfo.HasFlag(FtpMethodFlags.MustChangeWorkingDirectoryToPath))
                {
                    list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand(request.Method, str5), userCommand));
                }
                else
                {
                    list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand(request.Method, str3), userCommand));
                }
                if (!request.KeepAlive)
                {
                    list.Add(new CommandStream.PipelineEntry(this.FormatFtpCommand("QUIT", null)));
                }
            }
            return((CommandStream.PipelineEntry[])list.ToArray(typeof(CommandStream.PipelineEntry)));
        }
Ejemplo n.º 2
0
 internal bool HasFlag(CommandStream.PipelineEntryFlags flags)
 {
     return((this.Flags & flags) != 0);
 }
 internal PipelineEntry(string command, CommandStream.PipelineEntryFlags flags)
 {
     this.Command = command;
     this.Flags = flags;
 }
Ejemplo n.º 4
0
 internal PipelineEntry(string command, CommandStream.PipelineEntryFlags flags)
 {
     this.Command = command;
     this.Flags   = flags;
 }