3

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

SmbFile file = new SmbFile("smb://domain;username:P@ssword@abc.com/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.

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
user3897533
  • 417
  • 1
  • 8
  • 24
  • Never use credentials in the URL. That is for quick and dirty hacks. Use the NtlmPasswordAuthentication object. – squarewav Feb 08 '17 at 07:00

2 Answers2

3

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);
Nayana Priyankara
  • 1,392
  • 1
  • 18
  • 26
0

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

user3897533
  • 417
  • 1
  • 8
  • 24