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

GetPortV4() private method

Parses a response string for a port number

private GetPortV4 ( string responseString ) : int
responseString string
return int
        private int GetPortV4(string responseString)
        {
            string[] parsedList = responseString.Split(new char[] { ' ', '(', ',', ')' });

            // We need at least the status code and the port
            if (parsedList.Length <= 7)
            {
                throw new FormatException(SR.Format(SR.net_ftp_response_invalid_format, responseString));
            }

            int index = parsedList.Length - 1;
            // skip the last non-number token (e.g. terminating '.')
            if (!Char.IsNumber(parsedList[index], 0))
                index--;

            int port = Convert.ToByte(parsedList[index--], NumberFormatInfo.InvariantInfo);
            port = port |
                   (Convert.ToByte(parsedList[index--], NumberFormatInfo.InvariantInfo) << 8);

            return port;
        }