0

I am getting this error when i tried to read smb files.

PS

C:\Windows\system32> Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol


FeatureName      : SMB1Protocol 

DisplayName      : SMB 1.0/CIFS File Sharing Support

Description      : Support for the SMB 1.0/CIFS file sharing protocol, and the 

Computer Browser protocol.

RestartRequired  : Possible

State            : Enabled

CustomProperties :
                   ServerComponent\Description : Support for the SMB 1.0/CIFS 
file sharing protocol, and the Computer Browser protocol. ServerComponent\DisplayName : SMB 1.0/CIFS File Sharing Support
                   ServerComponent\Id : 487
                   ServerComponent\Type : Feature
                   ServerComponent\UniqueName : FS-SMB1
                   ServerComponent\Deploys\Update\Name : SMB1Protocol

It is saying my smb1 is enabled but I am still getting this error.

package shared_folder;

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import java.net.MalformedURLException;

public class Main {
    public static void main(String[] args) {
        String url = "smb://192.168.43.103/shared/";
        String userName = "shyam";
        String password = "shyam";
        String domain = null;
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, userName, password);
        try {
            doRecursiveLookup(new SmbFile(url, auth));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    /*
    * Recursively scans through the folder for files and prints the name of folder and file
    */
    public static void doRecursiveLookup(SmbFile smb) {
        try {
            if (smb.isDirectory()) {
                System.out.println(smb.getName());
                for (SmbFile f : smb.listFiles()) {
                    if (f.isDirectory()) {
                        doRecursiveLookup(f);
                    } else {
                        System.out.println("\t:" + f.getName());
                    }
                }
            } else {
                System.out.println("\t:" + smb.getName());
            }
        } catch (SmbException e) {
            e.printStackTrace();
        }
    }
}
Viktor Jovanovski
  • 1,513
  • 10
  • 26

1 Answers1

0

If you have Windows 10 you need to use and enable SMB2! (and optionally disable SMB1)

Possible solution: SmbException failed to connect hostname/IP_address throwing with proper credentials in Java

Soma Básthy
  • 110
  • 1
  • 8