【问题标题】:how to get full path with a smb file name when using jcifs使用jcifs时如何使用smb文件名获取完整路径
【发布时间】:2016-02-18 07:16:53
【问题描述】:

我阅读了 jCIFS 关于 smbfile 的 api,但我还没有找到如何仅使用文件名获取完整的 smb 路径。 我希望它返回“smb://aaa.bbb.com/sharedFolder/picture.jpg” 虽然它返回“smb://aaa.bbb.com/picture.jpg” 有代码:

String user = "user";
String password = "password";
String sharedFolder = "sharedFolder/";
String path = "smb://aaa.bbb.com/";
String fileName = "picture.jpg";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", user, password);
SmbFile smb = new SmbFile(path, auth);
SmbFile smbFile = new SmbFile(smb, fileName);
//String canonicalPath = smb.getCanonicalPath(); 
String filePath = smbFile.getUncPath();

【问题讨论】:

  • 我相信远程只能看到共享名称,而不是共享系统上共享文件夹的名称。

标签: java samba jcifs


【解决方案1】:

您没有在代码中使用变量sharedFolder。可以的,

String path = "smb://aaa.bbb.com/sharedFolder";
String fileName = "picture.jpg";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", user, password);
SmbFile smb = new SmbFile(path, auth);
SmbFile smbFile = new SmbFile(smb, fileName);

或

String sharedFolder = "sharedFolder/";
String path = "smb://aaa.bbb.com/" + sharedFolder; // <-- append it
String fileName = "picture.jpg";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", user, password);
SmbFile smb = new SmbFile(path, auth);
SmbFile smbFile = new SmbFile(smb, fileName);

【讨论】:

  • 谢谢你。对不起,我没有清楚地描述我的问题。我只知道文件名,不知道它在哪里。我希望 jcifs 返回完整路径,例如“pwd”命令。
  • pwd 命令告诉您当前的工作目录。您正在考虑locate 或find。您必须获取远程目录列表并希望它是一个公共文件夹,然后递归(或迭代)搜索 以查找匹配项。
猜你喜欢
  • 2010-09-30
  • 2010-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多