String user = "user:password";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
String path = "smb://my_machine_name/D/MyDev/test.txt";
SmbFile sFile = new SmbFile(path, auth);
SmbFileOutputStream sfos = new SmbFileOutputStream(sFile);
sfos.write("Test".getBytes());
sfos.close();
감사 :
이
public void downloadFromNetworkDrive3() throws MalformedURLException, SmbException, IOException {
String user = "domain;username:password";//domain name which you connect
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
String path = "smb://198.168.20.27/D$/MICROS/opera/export/OPERA/dinaamum/audit/Thumbs.db";
SmbFile sFile = new SmbFile(path, auth);
SmbFileOutputStream sfos;
SmbFileInputStream sfis;
try {
// sfos = new SmbFileOutputStream(sFile);
sfis = new SmbFileInputStream(sFile);
// sfos.write("hihowareyou".getBytes());
File tempFile = null;
String filePath = null;
filePath = "c://usr/local/cache/leelafiles";
tempFile = new File(filePath);
if (tempFile.exists()) {
} else {
tempFile.mkdirs();
}
tempFile = new File(filePath);
// File[] allFilesAndDirs = tempFile.listFiles();
FileOutputStream writer = new FileOutputStream(tempFile + File.separator + "Thumbs.db");
byte[] b = new byte[8192];
int n;
while ((n = sfis.read(b)) > 0) {
System.out.write(b, 0, n);
writer.write(b, 0, n);
}
sfis.close();
writer.close();
} catch (UnknownHostException ex) {
Logger.getLogger(ReportSchedulerJob.class.getName()).log(Level.SEVERE, null, ex);
}
}
이 어떤 경험을하지 마십시오 지금은 사용자 지정 라이브러리를 사용하는 것이, 나는에 포함해야합니까 .jar 파일이나 뭐? jar 파일은이 클래스들과 함께 어떻게 작동합니까? – Hazaart
[http://jcifs.samba.org/src/](http://jcifs.samba.org/src/)에서 jcifs-1.1.11.jar jar를 다운로드하고이 jar 파일을 빌드 경로에 추가하십시오. –
도메인이 있다면 도메인을 사용해야합니다 사용자 : 암호 –