Exemplo n.º 1
0
        private static string ToAbsoluteString(string scheme, string userName, string password, string host, uint port, string path = null, ParametersCollection parameters = null)
        {
            string portString = ((scheme == FtpUrlParser.Ssh) && (port == FtpUrlParser.SshPort)) ||
                                ((scheme == FtpUrlParser.Ftps) && (port == FtpUrlParser.FtpsPort)) ||
                                (port == FtpUrlParser.FtpPort) ? String.Empty : ":" + port;
            string passwordString = (!String.IsNullOrEmpty(password) ? String.Format(":{0}@", password) : (!String.IsNullOrEmpty(userName) ? "@" : String.Empty));

            if (path == null)
            {
                return(String.Format("{0}://{1}{2}{3}{4}/", scheme, userName, passwordString, host, portString));
            }

            return(String.Format(
                       "{0}://{1}{2}{3}{4}/{5}{6}",
                       scheme,
                       userName,
                       (!String.IsNullOrEmpty(password) ? String.Format(":{0}@", password) : (!String.IsNullOrEmpty(userName) ? "@" : String.Empty)),
                       host,
                       portString,
                       path,
                       (parameters != null ? String.Format(";{0}", parameters.ToString(FtpUrlParser.PathAllowedChars)) : String.Empty)));
        }