SMB操作

smb是一种网络文件协议,具体服务器配置参看

以下是一些常用的代码操作

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;

//认证
NtlmPasswordAuthentication ntl=new NtlmPasswordAuthentication("server","username","password");

//远程目录
String url="smb://"+"server"+"/"+"RemoteDirectory"+"/";
SmbFile remoteFile = new SmbFile(url,ntl);
if (remoteFile.exists() && remoteFile.isDirectory()) {
    try {
        remoteFile.list();//读取文件列表异常则无读权限
    } catch (Exception e) {
    }
    String testurl = url + "/smb" + "server" + "/";
    SmbFile test = new SmbFile(testurl,ntl);
    try {//写入临时文件异常无写权限
        test.createNewFile();
    } catch (Exception e) {
    } finally {
        test.delete();
    }
    return true;
} else {
    throw new GeneralExceptionRest("【" + name + "】配置错误,请检查配置参数");
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章