我想要连接到 SMB 服务器并浏览其文件,对于给定的路径,能够检索文件和文件夹的列表以及名称和权限。
我需要支持所有 SMB 方言,并且能够从我的代码中做到这一点。
代码大概如下:
smbClient.connect(serverInfo);
info = smbClient.getShare(shareName);
for(File file : info.getFiles) {
List<permission> permissions = file.getPermissions();
//do something
}
我尝试了一些选项,例如smbj https://github.com/hierynomus/smbj, impacket https://github.com/CoreSecurity/impacket, nmap https://nmap.org/, samba https://www.samba.org/samba/docs/current/man-html/smbclient.1.html但他们似乎都不能满足我的上述要求。
有没有办法使用 Java、Python 或任何我可以从 Java 代码调用的 Linux CLI 来实现上述目标?
我想它可以帮助你提高jcifs-ng。
**// Option 1 - SMB2 and SMB3:**
Properties prop = new Properties();
prop.put( "jcifs.smb.client.enableSMB2", "true");
prop.put( "jcifs.smb.client.disableSMB1", "false");
prop.put( "jcifs.traceResources", "true" );
Configuration config = new PropertyConfiguration(prop);
CIFSContext baseContext = new BaseContext(config);
CIFSContext contextWithCred = baseContext.withCredentials(new NtlmPasswordAuthentication(baseContext, domain, fileSystemInfo.getUsername(), fileSystemInfo.getPassword()));
SmbFile share = new SmbFile(fullPath.replace('\', '/'), contextWithCred);
if (!share.exists())
{
share.mkdirs();
}
share.close();
// 选项 2 - SMB1 和 CIFS:
SingletonContext context = SingletonContext.getInstance();
CIFSContext testCtx = context.withCredentials(
new NtlmPasswordAuthentication(
context, domain, fileSystemInfo.getUsername(), fileSystemInfo.getPassword()
)
);
SmbFile smbFile = new SmbFile(fullPath.replace('\', '/'), testCtx);
if (!smbFile.exists())
{
smbFile.mkdirs();
}
smbFile.close();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)