Reputation: 315
I have tried to list the files in the local path using the library smbj, But unable to list & copy the local files to the remote file server. I am getting the error. Shared the Error Log for reference.
My requirement is to change the "jcifs library" to "smbj library", the below sample code has been written for that.
Code:
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();
}
}
}
}
Error:
[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
Upvotes: 1
Views: 1451