文件批量傳輸組件git
文件批量傳輸組件適用於後臺服務器之間文件批量傳輸,能對某個文件夾進行自動監控、多線程批量傳輸、文件md5對比、錯誤重傳,也能知足中轉傳輸狀況(外網服務器把文件傳至中轉服務器,中轉服務器觸發再將文件傳送至目標服務器,傳輸結果消息返回給源服務器)。緩存
####一、兩臺主機之間傳輸配置: 兩臺主機之間傳輸時,發送文件主機要部署transfer_client項目;接收文件主機部署transfer_server項目。 #####a.發送文件的主機部署時,修改裏面的sysinfo.properties信息,而後打開transfer_client.bat進行文件夾監控:安全
#要監控的文件夾,當isMonitor=true有效 monitorPath=E:\\upload #是否用md5校驗 isMd5Check=true #是否中轉傳輸 isTransit=false #文件要發送給的主機ip,若是isTransit爲true是中轉服務器ip,false則爲目標ip sendToIp=localhost #文件要發送給的主機端口,若是isTransit爲true是中轉服務器端口,false則爲目標端口 sendToPort=111 #目標主機的ip,若是isTransit爲true則無效 targetIp= #目標主機的端口,若是isTransit爲true則無效 targetPort= #接收消息端口 receiveMsgPort= #定時任務每隔多少時間執行一次,單位毫秒 timerTaskPeriod=50000 #超時時間,毫秒 sendTimeout=18000000 #錯誤重傳次數 failResendCount=3 #是否進行安全權限驗證(若是文件接收服務器開啓了,必須開啓),爲true會開啓權限驗證,其內部爲增長一個驗證攔截器 isAuthorityCheck=false #權限驗證密鎖(要跟文件接收服務器對應),必須isAuthorityCheck爲true時有效。 authorityKey=password111 #緩存名,若是多個文件夾監放任務要用不一樣的緩存名,這裏因爲只有一個監放任務,可不寫 cacheName=cachename1
#####b.文件接收的主機是修改transfer_server項目下fileserver.xml,運行transfer_server.bat啓動:服務器
<?xml version="1.0" encoding="utf-8"?> <config> <!-- port:服務器接收端口 filePath:文件接收保存的路徑 soTimeout:文件接收超時時間 poolSize:文件接收線程池大小 isTransitServer:是否做爲中轉服務器 isAuthorityCheck:是否須要安全權限驗證(須要攔截器中加入AuthorityServerFilePlugin插件),若是爲true,客戶端必定也要開啓權限驗證,而且authorityKey要相等 authorityKey:密鎖,當isAuthorityCheck爲true有效 --> <fileserver port="111" filePath="E:\test\file" soTimeout="" poolSize="5" isTransitServer="false" isAuthorityCheck="false" authorityKey="password111" > <!-- 攔截器 --> <plugins> <plugin class="com.filetransfer.plugin.LogServerFilePlugin" ></plugin> <plugin class="com.filetransfer.plugin.AuthorityServerFilePlugin" > <param>serverReceiveControl</param> </plugin> </plugins> </fileserver> </config>
####二、中轉傳輸配置: 一臺主機把文件傳輸給中轉服務器,中轉服務器再把文件傳輸至第三臺主機時,接收文件主機和中轉主機都要部署transfer_server項目。文件發送主機使用transfer_client項目。多線程
#####a. 發送文件的主機部署transfer_client項目,修改sysinfo.properties信息,而後打開transfer_client.bat進行文件夾監控:工具
#要監控的文件夾,當isMonitor=true有效 monitorPath=E:\\upload #是否用md5校驗 isMd5Check=true #是否中轉傳輸 isTransit=true #文件要發送給的主機ip,若是isTransit爲true是中轉服務器ip,false則爲目標ip sendToIp=192.168.1.100 #文件要發送給的主機端口,若是isTransit爲true是中轉服務器端口,false則爲目標端口 sendToPort=111 #目標主機的ip,若是isTransit爲true則無效 targetIp= 192.168.1.101 #目標主機的端口,若是isTransit爲true則無效 targetPort=102 #接收消息端口 receiveMsgPort=201 #定時任務每隔多少時間執行一次,單位毫秒 timerTaskPeriod=50000 #超時時間,毫秒 sendTimeout=18000000 #錯誤重傳次數 failResendCount=3 #是否進行安全權限驗證(若是文件接收服務器開啓了,必須開啓),爲true會開啓權限驗證,其內部爲增長一個驗證攔截器 isAuthorityCheck=false #權限驗證密鎖(要跟文件接收服務器對應),必須isAuthorityCheck爲true時有效。 authorityKey=password111 #緩存名,若是多個文件夾監放任務要用不一樣的緩存名,這裏因爲只有一個監放任務,可不寫 cacheName=cachename1
#####b.中轉服務器部署transfer_server項目,修改配置信息fileserver.xml文件,打開transfer_server.bat進行啓動:ui
<?xml version="1.0" encoding="utf-8"?> <config> <!-- port:服務器接收端口 filePath:文件接收保存的路徑 soTimeout:文件接收超時時間 poolSize:文件接收線程池大小 isTransitServer:是否做爲中轉服務器 isAuthorityCheck:是否須要安全權限驗證(須要攔截器中加入AuthorityServerFilePlugin插件),若是爲true,客戶端必定也要開啓權限驗證,而且authorityKey要相等 authorityKey:密鎖,當isAuthorityCheck爲true有效 --> <fileserver port="111" filePath="E:\test\file" soTimeout="" poolSize="5" isTransitServer="true" isAuthorityCheck="false" authorityKey="password111" > <!-- 文件接收回調, class爲類的路徑 --> <!-- <fileReceiveCallBack class="com.filetransfer.server.fileserver.callback.TransitFileReceiveCallBack" > <param>serverReceiveControl</param> </fileReceiveCallBack> --> <!-- 中轉時發給源主機消息的適配器 --> <!-- <sendMessageAdapter class="com.filetransfer.client.message.defaultadapter.EdenSendMessageAdapter" > </sendMessageAdapter> --> <!-- 攔截器 --> <!-- 攔截器 --> <plugins> <plugin class="com.filetransfer.plugin.LogServerFilePlugin" ></plugin> <plugin class="com.filetransfer.plugin.AuthorityServerFilePlugin" > <param>serverReceiveControl</param> </plugin> </plugins> </fileserver> </config>
#####c. 目標文件接收的主機也是部署transfer_server項目,修改配置信息fileserver.xml文件,打開transfer_server.bat進行啓動:.net
<?xml version="1.0" encoding="utf-8"?> <config> <!-- port:服務器接收端口 filePath:文件接收保存的路徑 soTimeout:文件接收超時時間 poolSize:文件接收線程池大小 isTransitServer:是否做爲中轉服務器 isAuthorityCheck:是否須要安全權限驗證(須要攔截器中加入AuthorityServerFilePlugin插件),若是爲true,客戶端必定也要開啓權限驗證,而且authorityKey要相等 authorityKey:密鎖,當isAuthorityCheck爲true有效 --> <fileserver port="112" filePath="E:\cfile" soTimeout="" poolSize="5" isTransitServer="false" isAuthorityCheck="false" authorityKey="password111" > <!-- 攔截器 --> <plugins> <plugin class="com.filetransfer.plugin.LogServerFilePlugin" ></plugin> <plugin class="com.filetransfer.plugin.AuthorityServerFilePlugin" > <param>serverReceiveControl</param> </plugin> </plugins> </fileserver> </config>
做爲架包調用見: http://my.oschina.net/passerman/blog/715744
原理說明見: http://my.oschina.net/passerman/blog/715707
源碼見http://git.oschina.net/passer/transfer.core插件