goo blog サービス終了のお知らせ 

SentarohのAndroidアプリ開発で思ったこと

アプリ開発での思ったことや気づきの羅列

JCIFSとJCIFS-NGのサンプル

2019-09-26 16:54:37 | アプリ開発
JCIFSはSMB1だけなのでSMB2/3はJCIFS-NGを使う必要がある。
JCIFSの例:

String domain=null;
String user="youraccountname";
String password="yourpassword";
NtlmPasswordAuthentication auth=NtlmPasswordAuthentication(domain, user, pass);
SmbFile smb=new SmbFile("smb://yoursmbhost/yourshare/yourdirectory", auth);
InputStream is=smg.getInputStream();
int rc=0;
byte[] buff=new byte[1024];
while((rc=is.read(buff))>0) {
     your code
}

JCIFS-NGの例

String domain=null;
String user="youraccountname";
String password="yourpassword";
Properties prop = new Properties();
prop.setProperty("jcifs.smb.client.minVersion", "SMB210");
prop.setProperty("jcifs.smb.client.maxVersion", "SMB300");
BaseContext bc = new BaseContext(new PropertyConfiguration(prop));
NtlmPasswordAuthentication creds = new NtlmPasswordAuthentication(bc, domain, user, pass);
CIFSContext auth = bc.withCredentials(creds);
SmbFile smb=new SmbFile("smb://yoursmbhost/yourshare/yourdirectory", auth);
InputStream is=smg.getInputStream();
int rc=0;
byte[] buff=new byte[1024];
while((rc=is.read(buff))>0) {
     your code
}

最新の画像もっと見る