java远程共享文件访问jcifs解决密码中特殊符号问题
2016-07-14 18:49
846 查看
注意,先通过NtlmPasswordAuthentication进行验证,验证通过后用SmbFile 加入即可解决jcifs密码中的特殊符号问题
public void smbGet(String remoteUrl,String localDir) {
NtlmPasswordAuthentication auth = null ;
try {
String userName = "administrator";
String password = "admin?1";
String domainIP = "192.168.0.5";
InetAddress ip = InetAddress.getByName("192.168.0.5");
UniAddress myDomain = new UniAddress(ip);
auth = new NtlmPasswordAuthentication(domainIP, userName, password); //先登录验证
System.out.println("auth:"+auth.getDomain());
System.out.println("username:"+auth.getUsername());
System.out.println("password:"+auth.getPassword());
SmbSession.logon(myDomain,auth);
} catch (UnknownHostException e) {
e.printStackTrace();
System.out.println("111!!!");
} catch (SmbException e) {
e.printStackTrace();
System.out.println("222!!!");
}
InputStream in = null;
OutputStream out = null;
try {
SmbFile remoteFile = new SmbFile(remoteUrl,auth);
//注意,这句是关键,SmbFile 不支持特殊字符的密码,因此在这里放置
//remoteFile.connect();
if(remoteFile==null){
log.error("共享文件不存在!000");
return;
}
SmbFile localFile = new SmbFile(localDir,auth);
in = new BufferedInputStream(new SmbFileInputStream(remoteFile));
out = new BufferedOutputStream(new SmbFileOutputStream(localFile));
byte[] buffer = new byte[1024];
while(in.read(buffer)!=-1){
out.write(buffer);
buffer = new byte[1024];
}
}
catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void smbGet(String remoteUrl,String localDir) {
NtlmPasswordAuthentication auth = null ;
try {
String userName = "administrator";
String password = "admin?1";
String domainIP = "192.168.0.5";
InetAddress ip = InetAddress.getByName("192.168.0.5");
UniAddress myDomain = new UniAddress(ip);
auth = new NtlmPasswordAuthentication(domainIP, userName, password); //先登录验证
System.out.println("auth:"+auth.getDomain());
System.out.println("username:"+auth.getUsername());
System.out.println("password:"+auth.getPassword());
SmbSession.logon(myDomain,auth);
} catch (UnknownHostException e) {
e.printStackTrace();
System.out.println("111!!!");
} catch (SmbException e) {
e.printStackTrace();
System.out.println("222!!!");
}
InputStream in = null;
OutputStream out = null;
try {
SmbFile remoteFile = new SmbFile(remoteUrl,auth);
//注意,这句是关键,SmbFile 不支持特殊字符的密码,因此在这里放置
//remoteFile.connect();
if(remoteFile==null){
log.error("共享文件不存在!000");
return;
}
SmbFile localFile = new SmbFile(localDir,auth);
in = new BufferedInputStream(new SmbFileInputStream(remoteFile));
out = new BufferedOutputStream(new SmbFileOutputStream(localFile));
byte[] buffer = new byte[1024];
while(in.read(buffer)!=-1){
out.write(buffer);
buffer = new byte[1024];
}
}
catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
相关文章推荐
- JCIFS读取远程服务器文件过慢的解决方法
- 在 isilon 的 Samba 中接入 LDAP 认证并严格控制权限
- 在linux上安装配置samba服务器
- Hyper-v 高可用1: 建立SMB共享
- samba 最新漏洞代码POC
- Minolta350透過smb掃描到win2003 DC共享文件夾
- 在CentOS 6上用Samba Client访问windows共享文件夹
- Mac osx自动加载smb服务器
- 用jcifs连netapp的nas报用户名密码错的解决办法
- mac上的文件共享
- java基于SMB协议读取共享文件
- 利用SMB协议操作共享文件夹
- 基于SMB协议共享文件及文件夹的复制
- samba服务器配置
- windows,linux,smb共享权限问题
- Java操作远程共享资源(JCIFS)
- ubuntu-kalli 4.0.0 下创建SMB文件
- Ubuntu和CentOS超级简单的samba配置文件smb.conf
- Ubuntu下安装配置samba服务详细过程
- smb://#### 报错 this location could not be displayed