java jcifs出错,java.io.IOException: Invalid payload size: 405
Caused by: jcifs.smb.SmbAuthException: Logon failure: account currently disabled.
jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.
这是我遇到的错误。
原因是因为客户这边的系统是windows2016版本以上的,jcifs不适配这么高的版本。
更换类为smbj即可。
以下是我的实例代码 传参第一个是ip地址,用户名,密码,域名,共享文件的名称
static void uploadFile2(String hostname, String username, String password, String domain, String folderName){
String localFile = "D:\\local.txt"; // 本地要上传的文件
SmbConfig config = SmbConfig.builder()
.withTimeout(120, TimeUnit.SECONDS) // Timeout sets Read, Write, and Transact timeouts (default is 60 seconds)
.withSoTimeout(180, TimeUnit.SECONDS) // Socket Timeout (default is 0 seconds, blocks forever)
.build();
SMBClient client = new SMBClient(config);
try (com.hierynomus.smbj.connection.Connection connection = client.connect(hostname)) {
AuthenticationContext ac = new AuthenticationContext(username, password.toCharArray(), domain);
Session session = connection.authenticate(ac);
try (DiskShare share = (DiskShare) session.connectShare(folderName)) {
System.out.println("connect smbj success");
Set<AccessMask> accessMasks = new HashSet<>();
accessMasks.add(AccessMask.FILE_ADD_FILE);
Set<FileAttributes> attributes = new HashSet<>();
attributes.add(FileAttributes.FILE_ATTRIBUTE_NORMAL);
Set<SMB2ShareAccess> smb2ShareAccesses = new HashSet<>();
smb2ShareAccesses.add(SMB2ShareAccess.FILE_SHARE_WRITE);
Set<SMB2CreateOptions> smb2CreateOptions = new HashSet<>();
smb2CreateOptions.add(SMB2CreateOptions.FILE_RANDOM_ACCESS);
// System.out.println(1234);
com.hierynomus.smbj.share.File openFile = share.openFile("5.xlsx", accessMasks, attributes, smb2ShareAccesses, SMB2CreateDisposition.FILE_OVERWRITE_IF, smb2CreateOptions);
OutputStream oStream = openFile.getOutputStream();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(localFile));
byte[] buffer = new byte[1024];
int len = 0; //Read length
while ((len = in.read(buffer, 0, buffer.length)) != -1) {
oStream.write(buffer, 0, len);
}
oStream.flush();
oStream.close();
System.out.println("open file");
} catch (Exception e) {
System.out.println("err1");
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
OutsideTheIntranetDataServiceImpl.uploadFile2("192.168.13.193", "adm.iam.031", "microsate123.", "microsate.com", "iam"); }