文件批量傳輸組件直接使用說明

文件批量傳輸組件git

文件批量傳輸組件適用於後臺服務器之間文件批量傳輸,能對某個文件夾進行自動監控、多線程批量傳輸、文件md5對比、錯誤重傳,也能知足中轉傳輸狀況(外網服務器把文件傳至中轉服務器,中轉服務器觸發再將文件傳送至目標服務器,傳輸結果消息返回給源服務器)。緩存

  1. 可直接獨立成單獨的客戶端和服務端系統,支持配置。
  2. 可做爲工具架包,其餘系統可調用方法進行文件傳輸相關操做
  3. 支持文件夾監控,自動傳輸
  4. 支持各類類型的文件多線程傳輸
  5. 支持文件md5對比,錯誤重傳
  6. 支持中轉傳輸
  7. 支持安全權限驗證
  8. 可自定義攔截器、回調類,易擴展

直接使用(編譯好的文件在build文件夾下):

####一、兩臺主機之間傳輸配置: 兩臺主機之間傳輸時,發送文件主機要部署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插件

相關文章
相關標籤/搜索