日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

kettle下载windows共享文件夹到本地

發布時間:2023/12/31 windows 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 kettle下载windows共享文件夹到本地 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.將jar包導入到kettle的lib目錄

下載地址:https://mvnrepository.com/artifact/jcifs/jcifs/1.3.17

2.建立轉換

java代碼如下:

import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;import org.slf4j.Logger; import org.slf4j.LoggerFactory;import jcifs.smb.NtlmPasswordAuthentication; import jcifs.smb.SmbFile; import jcifs.smb.SmbFileInputStream; import jcifs.smb.SmbFileOutputStream;public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {if (first) {first = false;}Object[] r = getRow();if (r == null) {setOutputDone();return false;}// It is always safest to call createOutputRow() to ensure that your output row's Object[] is large// enough to handle any new fields you are creating in this step.r = createOutputRow(r, data.outputRowMeta.size());//我的代碼//smb://xxx:xxx/xxxx.xlsx //xxx:xxx是共享機器的用戶名密碼try{smbGet("smb://xxx:xxx/xxxx.xlsx", "D:/");} catch (Exception e){}putRow(data.outputRowMeta, r);return true; }/*** @Title smbGet* @Param shareUrl 共享目錄中的文件路徑,如smb://xxx:xxx/xxxx.xlsx* @Param localDirectory 本地目錄,如D:/*/ public static void smbGet(String shareUrl, String localDirectory) throws Exception {String USER_DOMAIN = null;String USER_ACCOUNT = null;String USER_PWS = null;NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(USER_DOMAIN, USER_ACCOUNT,USER_PWS);SmbFile remoteFile = new SmbFile(shareUrl, auth);if (!remoteFile.exists()) {return;}// 有文件的時候再初始化輸入輸出流InputStream in = null;OutputStream out = null;try {String fileName = remoteFile.getName();File localFile = new File(localDirectory + File.separator + fileName);File fileParent = localFile.getParentFile();if (null != fileParent && !fileParent.exists()) {fileParent.mkdirs();}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];}out.flush(); //刷新緩沖區輸出流} catch (Exception e) {e.printStackTrace();} finally {out.close();in.close();}}/*** * @Title smbPut* @Description 向共享目錄上傳文件* @Param shareDirectory 共享目錄* @Param localFilePath 本地目錄中的文件路徑* @date 2019-01-10 20:16*/public static void smbPut(String shareDirectory, String localFilePath) {InputStream in = null;OutputStream out = null;try {File localFile = new File(localFilePath);String fileName = localFile.getName();SmbFile remoteFile = new SmbFile(shareDirectory + "/" + fileName);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];}out.flush();} catch (Exception e) {e.printStackTrace();} finally {try {out.close();in.close();} catch (IOException e) {e.printStackTrace();}}}

java代碼參考:

https://www.cnblogs.com/tianhyapply/p/3721381.html

總結

以上是生活随笔為你收集整理的kettle下载windows共享文件夹到本地的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。