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 + "】配置錯誤,請檢查配置參數");
}

 

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