栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

java smb共享 无密码

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java smb共享 无密码

在本地写好的mapreduce程序想要连接远程服务器进行执行, 但在执行时: 连接远程服务器时出现一下异常:java.net.UnknownHostException: unknown host: master

I'm trying to copy a file from a local directory to a network

on a windows box. I'm using jcifs 1.3.17. I successfully get a connection to the destination, actually create the file there, get a "canWrite" status of "true", but when I try to copy the contents of the local file to the remote file, I get the following error:

jcifs.smb.SmbException: Failed to connect to server

java.net.UnknownHostException: ..__MSBROWSE__.<01>

at jcifs.netbios.NbtAddress.doNameQuery(NbtAddress.java:317)

. . .

code snippet:

SmbFile source = new SmbFile(original);

SmbFile dest = new SmbFile (target,auth);

dest.createNewFile();

boolean canWrite = dest.canWrite();

source.copyTo(dest);

I don't get it... if I can create the file on the destination and smb sees that I can write to it, why does the doCopy fail?

java

smb

unknown-host

asked May 13 '15 at 14:20

scooter4j 13 5

|

1 Answers

1

解决方法

I don't get it too but... try this. It works!现象 在Mac上启动tomcat时,报了如下错误: Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.Unkn

String source = "smb://SERVER/PATH/FILE";

NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "USERNAME", "PASSWORD");

SmbFile sourceFile = new SmbFile(source, auth);

String destination = "LOCAL_PATH_TO_FILE";

byte[] buffer;

int length;

try {

FileOutputStream fileOutputStream = new FileOutputStream(destination);

InputStream fileInputStream = sourceFile.getInputStream();

try {

buffer = new byte[16 * 1024 * 1024];

while ((length = fileInputStream.read(buffer)) > 0) {

fileOutputStream.write(buffer, 0, length);

}

} finally {

fileInputStream.close();

fileOutputStream.close();

}

} catch (SmbException e) {

// Error handling.

} catch (FileNotFoundException e) {

// Error handling.

} catch (IOException e) {

// Error handling.

}

answered Jul 15 '15 at 10:16

iaforek 529 1 4 17 2   I would replace try-finally with try with resource. –

rkosegi Jul 15 '15 at 10:19      @rkosegi You are right. Use try-with-resource when you are using Java 1.7. My solution is for 1.6. –

iaforek Jul 15 '15 at 12:21

|

錯誤日志: jcifs.smb.SmbException: NTLMv2 requires extended security (jcifs.smb.client.useExtendedSecurity must be true if jcifs.smb.lmCompatibility >=

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/911351.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号