user3897533
user3897533

Reputation: 477

SmbFile URL path with password having an @

I am using the JCIFS library and I have the samba file URL as

SmbFile file = new SmbFile("smb://domain;username:P@[email protected]/share/filename.txt")
file.connect

Notice the password has an @. Samba file connect is failing giving an java.net.UnknownHostException. Other than parsing the URL and passing auth seperately using NtlmAuthentication, is there any other way...

In the Format URL I tried putting square brackets and that did not help.

Upvotes: 3

Views: 3182

Answers (2)

Nayana Priyankara
Nayana Priyankara

Reputation: 1422

URL Encode the password as below

URLEncoder.encode(password, "UTF-8");

this will encode your password to -P%40ssword This called present encoding.Check this Wikipedia Link to learn more about present encoding.

But this is not a good practice.Create a NtlmPasswordAuthentication to set authentication details.

NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, username, password);
String path ="abc.com/share/filename.txt";
SmbFile file = new SmbFile(path,auth);

Upvotes: 3

user3897533
user3897533

Reputation: 477

I did UrlEncode of the password and that solved the problem.

Upvotes: 0

Related Questions