0

Why is my java class not connecting to remote drive using smb?

    String user = "user1";
    String pass ="pass234";

    String sharedFolder="c$\\WebDocs2\\AutoFrameworkResults\\";
    String path= "smb:" +"\\" + "\\192.xx.1.xx\\" + sharedFolder + "Example.txt";
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",user, pass);
    SmbFile smbFile = new SmbFile(path,auth);
    SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
    smbfos.write("testing....and writing to a file".getBytes());
    System.out.println("completed ...nice !");

Im getting the following Exception (But the username and password credentials are correct)?`

Exception in thread "main" jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.
    at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:406)
    at jcifs.smb.SmbSession.send(SmbSession.java:218)
    at jcifs.smb.SmbTree.treeConnect(SmbTree.java:176)
Gbru
  • 1,065
  • 3
  • 24
  • 56
  • Put up a [mcve] please. And maybe maybe because the user is unknown or the password isn't matching? – GhostCat May 10 '17 at 11:06
  • @Jens i have tried removing the first set of \\ but thats not the problem :/ – Gbru May 10 '17 at 11:08
  • @Jens this is not a duplicate because i have followed the instructions listed in the ticket yet still face a username and password problem – Gbru May 10 '17 at 11:15
  • Try to change `new NtlmPasswordAuthentication("",user, pass)` to `new NtlmPasswordAuthentication(user+":"+pass)` – Eritrean May 10 '17 at 11:16
  • @Eritrean thanks for your comment im afraid it didnt work – Gbru May 10 '17 at 11:18

0 Answers0