Why do I get 'System.UriFormatException: Invalid URI: Invalid port specified.' when using an IPv6 URI?
c#, ftp, ipv6, uri
Solution
From RFC 2732:
To use a literal IPv6 address in a URL, the literal address should be enclosed in "[" and "]" characters.
For example, this works fine:
var uri = new Uri("ftp://[1111:2222:3333::43]/testing/1kb.zip");
If you want to specify the port, it needs to be outside the square brackets:
var uri = new Uri("ftp://[1111:2222:3333::43]:100/testing/1kb.zip");
Problem
Why does this `var uri = new Uri("ftp://1111:2222:3333::43/testing/1kb.zip");` Throw this exception? System.UriFormatException: Invalid URI: Invalid port specified. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)