1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| NtlmPasswordAuthentication auth = new
NtlmPasswordAuthentication("192.168.1.2", "user", "123456");
SmbFile originalfile = new SmbFile("smb://192.168.1.2/c$/CV/testing.txt/",auth);
NtlmPasswordAuthentication auth1 = new
NtlmPasswordAuthentication("192.168.1.3", "user", "essadiki_ista");
SmbFile destinationfile = new SmbFile("smb://192.168.1.3/c$/dir/",auth1);
SmbFileInputStream in = null; // canal d'entrée
SmbFileOutputStream out = null; // canal de sortie
try {
// Init
in = new SmbFileInputStream(originalfile);
out = new SmbFileOutputStream(destinationfile);
// Lecture par segment de 0.5Mo
byte buffer[]= new byte[512*1024];
int nbLecture;
while( (nbLecture = in.read(buffer)) != -1 ) {
out.write(buffer, 0, nbLecture);
}
System.out.println("File " + originalfile.getName() + " copied to : " + destinationfile);
} catch (IOException e) {
e.printStackTrace(); // n'importe quelle exception
} finally { // finalement on ferme
if(in != null) {
try {
in.close();
} catch (IOException e) {}
}
if(out != null) {
try {
out.close();
} catch (IOException e) {}
}
} |
Partager