Esempio n. 1
0
        public void CloneTest()
        {
            string url         = "ftp://ftp.contoso.com/";
            string username    = "******";
            string password    = "******";
            bool   enableSsl   = false;
            string headerName  = "Accept-Range";
            string headerValue = "bytes";

            FtpWebRequest original = (FtpWebRequest)WebRequest.Create(url);

            original.Credentials = new NetworkCredential(username, password);
            original.EnableSsl   = enableSsl;
            original.Headers.Add(headerName, headerValue);

            FtpWebRequest clone = original.Clone();

            NetworkCredential cloneCredentials = (NetworkCredential)clone.Credentials;

            Assert.AreEqual(url, clone.RequestUri.AbsoluteUri);
            Assert.AreEqual(username, cloneCredentials.UserName);
            Assert.AreEqual(password, cloneCredentials.Password);
            Assert.AreEqual(enableSsl, clone.EnableSsl);
            Assert.AreEqual(1, clone.Headers.Count);
        }
Esempio n. 2
0
        /// <summary>
        /// Creating a new FtpWebRequest.
        /// Clones or creates request.
        /// </summary>
        /// <returns>FtpWebRequest</returns>
        private FtpWebRequest CreateRequest()
        {
            FtpWebRequest request;

            // If _request is set, clone the request
            if (_request != null)
            {
                // Create clone of request
                request = _request.Clone();
            }
            // If _request is unset, create new request
            else
            {
                // Default FtpWebRequest with URI
                request = (FtpWebRequest)WebRequest.Create(_requestUri);
            }

            return(request);
        }