文件批量傳輸組件做爲架包使用說明

    文件批量傳輸組件可做爲一個工具架包,其餘系統可調用方法進行文件傳輸相關操做,能對某個文件夾進行自動監控、多線程批量傳輸、文件md5對比、錯誤重傳等。文件批量傳輸組件做爲系統直接使用見http://my.oschina.net/passerman/blog/715642。多線程

    1.      發送單文件不中轉時工具

發送端代碼例子:.net

FileClientConfig clientConfig=new FileClientConfig(false,true,false,"localhost",112);
/*		clientConfig.setAuthorityCheck(true);//權限驗證
		clientConfig.setAuthorityKey("password111"); //驗證密鎖
*/		FileTransferClient fileTransferClient=new FileTransferClient(clientConfig);
		 fileTransferClient.init();
		 //要發送的文件
		String absolutePath="E:\\log.txt";
		FileInfo fileInfo=new FileInfo();
    	fileInfo.setFilePath(absolutePath);
		fileTransferClient.sendFile("\\log2.txt", fileInfo); //想保存的文件名

接收端代碼例子:線程

//只做爲接收主機	
		FileServerConfig fileServerConfig=new FileServerConfig("d:\\csavefile", 112, false);
		ServerReceiveControl serverReceiveControl=new ServerReceiveControl(fileServerConfig);
		//serverReceiveControl.addServerFilePlugin(new ServerFilePlugin());
		//serverReceiveControl.addServerFilePlugin(new DemoServerFilePlugin());
		ReceiveServerPulse ReceiveServerPulse=new ReceiveServerPulse( serverReceiveControl);
		ReceiveServerPulse.start();

    2.  監控文件夾不中轉時code

發送端代碼例子:server

//不中轉監控傳輸
		FileClientConfig clientConfig=new FileClientConfig("E:\\upload",true,true,false,"localhost",111);
		clientConfig.setTimerTaskPeriod(1000*30);//每30秒監控一次
		/*clientConfig.setAuthorityCheck(true);//權限驗證
		clientConfig.setAuthorityKey("password111"); //驗證密鎖
*/		FileTransferClient fileTransferClient=new FileTransferClient(clientConfig);
		/*fileTransferClient.getTransferControl().addClientFilePlugin(new DemoClientFilePlugin(fileTransferClient.getTransferControl()));//增長自定義攔截器
		fileTransferClient.getTransferControl().addClientFilePlugin(new AuthorityClientFilePlugin(fileTransferClient.getTransferControl())); //添加驗證攔截器
		*/
        fileTransferClient.init();

接收端代碼例子:blog

    與1相同。md5

    3.  監控文件夾中轉傳輸get

發送端代碼例子:it

FileClientConfig clientConfig=new FileClientConfig("E:\\upload", true, true, true, "localhost", 111,"localhost",112,201);
		clientConfig.setTimerTaskPeriod(1000*30);
		clientConfig.setAuthorityCheck(true);//權限驗證
		clientConfig.setAuthorityKey("password111"); //驗證密鎖
		FileTransferClient fileTransferClient=new FileTransferClient(clientConfig);
		fileTransferClient.getTransferControl().addClientFilePlugin(new DemoClientFilePlugin(fileTransferClient.getTransferControl()));
		fileTransferClient.getTransferControl().addClientFilePlugin(new AuthorityClientFilePlugin(fileTransferClient.getTransferControl())); //添加驗證攔截器
		fileTransferClient.init();

中轉端代碼例子:

FileServerConfig fileServerConfig=new FileServerConfig("d:\\csavefile", 111, true); //文件接收配置類
		ServerReceiveControl serverReceiveControl=new ServerReceiveControl(fileServerConfig); //文件接收控制類
		serverReceiveControl.addServerFilePlugin(new ServerFilePlugin());
		serverReceiveControl.addServerFilePlugin(new DemoServerFilePlugin());
		ReceiveServerPulse ReceiveServerPulse=new ReceiveServerPulse(serverReceiveControl);
		ReceiveServerPulse.start();

目標接收端代碼例子:

//只做爲接收主機	
		FileServerConfig fileServerConfig=new FileServerConfig("d:\\csavefile", 112, false);
		ServerReceiveControl serverReceiveControl=new ServerReceiveControl(fileServerConfig);
		ReceiveServerPulse ReceiveServerPulse=new ReceiveServerPulse( serverReceiveControl);
		ReceiveServerPulse.start();
相關文章
相關標籤/搜索