internal FtpWebRequest(Uri uri)
 {
     new WebPermission(NetworkAccess.Connect, uri).Demand();
     if (Logging.On)
     {
         Logging.PrintInfo(Logging.Web, this, ".ctor", uri.ToString());
     }
     if (uri.Scheme != Uri.UriSchemeFtp)
     {
         throw new ArgumentOutOfRangeException("uri");
     }
     this.m_TimerCallback = new TimerThread.Callback(this.TimerCallback);
     this.m_SyncObject = new object();
     NetworkCredential defaultFtpNetworkCredential = null;
     this.m_Uri = uri;
     this.m_MethodInfo = FtpMethodInfo.GetMethodInfo("RETR");
     if ((this.m_Uri.UserInfo != null) && (this.m_Uri.UserInfo.Length != 0))
     {
         string userInfo = this.m_Uri.UserInfo;
         string userName = userInfo;
         string password = "";
         int index = userInfo.IndexOf(':');
         if (index != -1)
         {
             userName = Uri.UnescapeDataString(userInfo.Substring(0, index));
             index++;
             password = Uri.UnescapeDataString(userInfo.Substring(index, userInfo.Length - index));
         }
         defaultFtpNetworkCredential = new NetworkCredential(userName, password);
     }
     if (defaultFtpNetworkCredential == null)
     {
         defaultFtpNetworkCredential = DefaultFtpNetworkCredential;
     }
     this.m_AuthInfo = defaultFtpNetworkCredential;
     base.SetupCacheProtocol(this.m_Uri);
 }
Ejemplo n.º 2
0
        internal FtpWebRequest(Uri uri)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Info(this, uri);

            if ((object)uri.Scheme != (object)Uri.UriSchemeFtp)
                throw new ArgumentOutOfRangeException(nameof(uri));

            _timerCallback = new TimerThread.Callback(TimerCallback);
            _syncObject = new object();

            NetworkCredential networkCredential = null;
            _uri = uri;
            _methodInfo = FtpMethodInfo.GetMethodInfo(WebRequestMethods.Ftp.DownloadFile);
            if (_uri.UserInfo != null && _uri.UserInfo.Length != 0)
            {
                string userInfo = _uri.UserInfo;
                string username = userInfo;
                string password = "";
                int index = userInfo.IndexOf(':');
                if (index != -1)
                {
                    username = Uri.UnescapeDataString(userInfo.Substring(0, index));
                    index++; // skip ':'
                    password = Uri.UnescapeDataString(userInfo.Substring(index, userInfo.Length - index));
                }
                networkCredential = new NetworkCredential(username, password);
            }
            if (networkCredential == null)
            {
                networkCredential = s_defaultFtpNetworkCredential;
            }
            _authInfo = networkCredential;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <para>
        /// Initializes a new instance of the <see cref='System.Net.FtpWebRequest'/>
        /// class.
        /// </para>
        /// </summary>
        internal FtpWebRequest(Uri uri) {
           (new WebPermission(NetworkAccess.Connect, uri)).Demand();

           if (Logging.On) Logging.PrintInfo(Logging.Web, this, ".ctor", uri.ToString());

           if ((object)uri.Scheme != (object)Uri.UriSchemeFtp)
               throw new ArgumentOutOfRangeException("uri");

            m_TimerCallback = new TimerThread.Callback(TimerCallback);
            m_SyncObject = new object();

            NetworkCredential networkCredential = null;
            m_Uri = uri;
            m_MethodInfo = FtpMethodInfo.GetMethodInfo(WebRequestMethods.Ftp.DownloadFile);
            if (m_Uri.UserInfo != null && m_Uri.UserInfo.Length != 0) {
                string userInfo = m_Uri.UserInfo;
                string username = userInfo;
                string password = "";
                int index = userInfo.IndexOf(':');
                if (index != -1) {
                    username = Uri.UnescapeDataString(userInfo.Substring(0, index));
                    index++; // skip ':'
                    password = Uri.UnescapeDataString(userInfo.Substring(index, userInfo.Length - index));
                }
                networkCredential = new NetworkCredential(username, password);
            }
            if (networkCredential == null) {
                networkCredential = DefaultFtpNetworkCredential;
            }
            m_AuthInfo = networkCredential;
            SetupCacheProtocol(m_Uri);
        }