1

I am trying to connect to a shared network drive using SmbFile in java. This is my code:

        String path = "smb://QTPSRVRCH22/folder";
        
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain", "user", "password");
        
        SmbFile dir = new SmbFile(path, auth);

        for (SmbFile f : dir.listFiles()) {
            System.out.println(f.getName());
        }

However, I am getting these errors:

jcifs.smb.SmbException: Failed to connect: QTPSRVRCH22/10.13.147.114
jcifs.util.transport.TransportException
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:210)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at jcifs.util.transport.Transport.readn(Transport.java:29)
    at jcifs.smb.SmbTransport.peekKey(SmbTransport.java:388)
    at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:288)
    at jcifs.smb.SmbTransport.doConnect(SmbTransport.java:319)
    at jcifs.util.transport.Transport.run(Transport.java:241)
    at java.lang.Thread.run(Thread.java:748)
    at jcifs.util.transport.Transport.run(Transport.java:258)
    at java.lang.Thread.run(Thread.java:748)

I am on a mac, and I am able to connect to the server directly when I go to Finder > Go > Connect to Server with this server address smb://QTPSRVRCH22. Once I connect, I'm able to see the expected folders and files. I believe QTPSRVRCH22 is a windows server, if that matters.

What am I missing in my java code? Thanks in advance

user1893649
  • 167
  • 2
  • 14
  • I had the same issue, but I solved it here: https://stackoverflow.com/questions/68529198/smbexception-failed-to-connect-hostname-ip-address-throwing-with-proper-credenti (It works on Windows 10) – Soma Básthy Jul 28 '21 at 07:44

0 Answers0