我尝试使用库 smbj 列出本地路径中的文件,但无法列出并将本地文件复制到远程文件服务器。我收到错误消息。共享错误日志以供参考。
我的要求是将“jcifs library”更改为“smbj library”,为此编写了以下示例代码。
代码:
import com.hierynomus.msfscc.fileinformation.FileIdBothDirectoryInformation;
import com.hierynomus.smbj.SMBClient;
import com.hierynomus.smbj.SmbConfig;
import com.hierynomus.smbj.auth.AuthenticationContext;
import com.hierynomus.smbj.connection.Connection;
import com.hierynomus.smbj.session.Session;
import com.hierynomus.smbj.share.DiskShare;
public class test1 {
public static void main(String[] args) throws Exception {
try {
SmbConfig cfg = SmbConfig.builder()
.withMultiProtocolNegotiate(true)
.withSigningRequired(false)
.withDfsEnabled(false)
.build();
final String Local_SHARE_NAME = "/";
final String LOCAL_PATH = "home//usename//myfolder";
SMBClient client = new SMBClient(cfg);
try (Connection connection = client.connect("Remote_Server_IP")) { //x.x.x.x
AuthenticationContext ac = new AuthenticationContext("user", "pwd".toCharArray(), "Domainname");
Session session = connection.authenticate(ac);
try (DiskShare share = (DiskShare) session.connectShare(Local_SHARE_NAME)) {
for (FileIdBothDirectoryInformation f : share.list(LOCAL_PATH)) {
System.out.println("File : " + f.getFileName());
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
client.close();
}
}
}
}
错误:
[main] INFO com.hierynomus.smbj.connection.PacketEncryptor - Initialized PacketEncryptor with Cipher
[main] INFO com.hierynomus.smbj.connection.Connection - Successfully connected to: x.x.x.x
[main] INFO com.hierynomus.smbj.connection.SMBSessionBuilder - Successfully authenticated xxxx on x.x.x.x, session is 164423090532534600
com.hierynomus.mssmb2.SMBApiException: STATUS_BAD_NETWORK_NAME (0xc00000cc): Could not connect to \\x.x.x.x\/
at com.hierynomus.smbj.session.Session.connectTree(Session.java:151)
[main] INFO com.hierynomus.smbj.session.Session - Logging off session 164423090532534600 from host x.x.x.x
[main] INFO com.hierynomus.smbj.connection.Connection - Closed connection to x.x.x.x
[Packet Reader for x.x.x.x] INFO com.hierynomus.smbj.transport.tcp.direct.DirectTcpPacketReader - Thread[Packet Reader for x.x.x.x,5,main] stopped.
[main] INFO com.hierynomus.smbj.SMBClient - Going to close all remaining connections