public static void smbPut(String localFileName) {
InputStream in = null;
OutputStream out = null;
try {
File localFile = new File(本地路径+""+localFileName+".csv");
String fileName = localFile.getName();
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, jd_username, jd_pwd);
SmbFile remoteFile = new SmbFile(server_file+fileName, auth);
in = new BufferedInputStream(new FileInputStream(localFile));
out = new BufferedOutputStream(new SmbFileOutputStream(remoteFile));
byte[] buffer = new byte[1024];
while(in.read(buffer)!=-1){
out.write(buffer);
buffer = new byte[1024];
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void smbGet(String remoteUrl,String localDir) {
InputStream in = null;
OutputStream out = null;
try {
SmbFile remoteFile = new SmbFile(remoteUrl);
String fileName = remoteFile.getName();
File localFile = new File(localDir+File.separator+fileName);
in = new BufferedInputStream(new SmbFileInputStream(remoteFile));
out = new BufferedOutputStream(new FileOutputStream(localFile));
byte[] buffer = new byte[1024];
while(in.read(buffer)!=-1){
out.write(buffer);
buffer = new byte[1024];
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void deleteFile(String remoteUrl, String fileName, String userName, String pwd) {
SmbFile SmbFile;
try {
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, userName, pwd);
SmbFile = new SmbFile(remoteUrl + "/" + fileName, auth);
if (SmbFile.exists()) {
SmbFile.delete();
}
} catch (MalformedURLException | SmbException e) {
e.printStackTrace();
}
}