Parse FTP url

M

MarkusJNZ

Hi all, does anyone know how I can parse an ftp url to retrieve the
server, login and password?

e.g. given a ftp url like

ftp://ftplogin:[email protected]

I can get out the following info

server = subdomain.domain.com
password = mypass
login = ftplogin

I can successfully get the url etc by doing string parsing etc but I
would like a better way which is not open to interpretation.

e.g. Someone might have a @ or a : in their password then the string
parsing may run into problems.

TIA
Markus

=================================
jhgklioplsjdujehhrejhjrejhekdsdlkasdlerksdksd
 
J

Juan T. Llibre

re:
I notice UserInfo pulls out the username and password:

Yes, UserInfo pulls them out.
Then, with GetComponents, you can get the host server's name:

Sub Page_Load()
Dim uriAddress As New Uri("ftp://ftplogin:[email protected]/")
Label1.Text = uriAddress.UserInfo
Label2.Text = uriAddress.GetComponents(UriComponents.Host, UriFormat.Unescaped)
End Sub

See an example running at : http://asp.net.do/test/UriComponents.aspx





Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top