如何在 SMB 中定义路径

how to define path in SMB

我有一个场景需要将文件从我的机器发送到某个共享位置。当我在我的机器上看到共享位置时 (windows 7) 显示为 N: drive.

O/P for net use 命令找到它的遥控器,我得到它作为 \smb\ds

我正在编写代码以将字符串写入远程位置的文件,即 N:\TESTING_GOING_ON\test.txt 它是这样的,

String user = "abcd:XXXXX";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
String path = "smb//ds/TESTING_GOING_ON/test.txt";
SmbFile sFile = new SmbFile(path,auth);
try (SmbFileOutputStream sfos = new SmbFileOutputStream(sFile)) {
    sfos.write(str.getBytes());
    sfos.close();
}

使用jcifs.smb.* 但是,对于路径,我要么没有定义协议,要么无法连接。

所以有人可以让我知道我使用的路径是否正确。 如果不正确怎么办

documentation 看起来很清楚(虽然我没有测试过)。示例格式为

smb://storage15/public/foo.txt

所以对你来说,应该是

smb://smb/ds/TESTING_GOING_ON/test.txt

假设您的 SMB 服务器实际上被命名为 smb,这将很有趣。