1

I was trying to implement the functionality of transferring local files to a network drive using jcifs library but upon running the program on the command line I was receiving following exception:

Exception in  thread "main"  java.lang.NullPointerException
jcifs.smb.ServerMessageBlock.writeString(ServerMessageBlock.java: 202)

To understand the error I tried debugging the code on eclipse and while doing so at line: NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication("xxxxxx.xx.com",username,password);

I received an exception stating ClassNotFoundException. But I have the jcifs.jar in the build path.

A quick google search for 'ntlmpasswordauthentication' classnotfoundexception landed me on two threads with same issue but no resolution.

Please let me know how can I resolve this.

Thank you

Here is the whole function, just in case needed:

private static void TransferFiles()
{
 File transfer_files = new File  (sourcepath);
 File[] files = transfer_files.listFiles();

 String username = properties.getProperty("user");
 String password = properties.getProperty("password");
 String source = sourcepath;

 SmbFileOutputStream outputStream = null;
 FileInputStream inputStream = null;
 SmbFile copyFile = null;
 byte[] buffer = new byte[16*1024*1024];
 int length = 0;

 jcifs.smb.NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication("xxxxxxx",username,password);
 try 
 {
    copyFile = new SmbFile(destinationpath,authentication);
}
 catch (MalformedURLException e) 
 {
    e.printStackTrace();
 }

 try 
 {
    outputStream = new SmbFileOutputStream(copyFile);
 }
 catch (SmbException | MalformedURLException | UnknownHostException e) 
 {
    e.printStackTrace();
 }

 try 
 {
    inputStream = new FileInputStream(sourceFile);
}
catch (FileNotFoundException e1) 
 {
    e1.printStackTrace();
}

 try 
    {
        while((length = inputStream.read(buffer))>0)
        {
            outputStream.write(buffer, 0, length);
        }
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    }

    try 
    {   
        inputStream.close();
        outputStream.close();
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    }
2
  • are you importing NtlmPasswordAuthentication
    – BevynQ
    Oct 9, 2014 at 22:01
  • Yes I have imported NtlmPasswordAuthentication Oct 10, 2014 at 14:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.