System.Net.FtpControlStream.GetPortV6 C# (CSharp) Method

GetPortV6() private method

Parses a response string for a port number

private GetPortV6 ( string responseString ) : int
responseString string
return int
        private int GetPortV6(string responseString)
        {
            int pos1 = responseString.LastIndexOf("(");
            int pos2 = responseString.LastIndexOf(")");
            if (pos1 == -1 || pos2 <= pos1)
                throw new FormatException(SR.Format(SR.net_ftp_response_invalid_format, responseString));

            // addressInfo will contain a string of format "|||<tcp-port>|"
            string addressInfo = responseString.Substring(pos1 + 1, pos2 - pos1 - 1);

            string[] parsedList = addressInfo.Split(new char[] { '|' });
            if (parsedList.Length < 4)
                throw new FormatException(SR.Format(SR.net_ftp_response_invalid_format, responseString));

            return Convert.ToInt32(parsedList[3], NumberFormatInfo.InvariantInfo);
        }