/// <summary> /// 使用花生壳预设服务器进行的测试,请替换 /// </summary> /// <param name="args"></param> static void Main(string[] args) { var port = Convert.ToInt32(Console.ReadLine()); while (Console.ReadLine() != "") { Console.WriteLine("开始连接"); if (engine != null) { engine.Dispose(); } engine = null; if (Console.ReadLine() == "send") { engine = new TransferFileEngine(EngineModel.AsServer, "any", port); Console.WriteLine("准备发送"); } else { engine = new TransferFileEngine(EngineModel.AsClient, "2y155s0805.51mypc.cn", port); Console.WriteLine("等待接收"); } Init(); engine.Connect(); } }
private static void SynFile(string xx) { var cstr = new StringBuilder(); var verFiles = HttpUtil.GetAllElements(xx, "<file>", "</file>"); foreach (var f in verFiles) { var fver = HttpUtil.GetElement(f, "<version>", "</version>"); var fname = HttpUtil.GetElement(f, "<name>", "</name>"); var localFile = HttpUtil.GetMD5ByMD5CryptoService(fname); if (fver != localFile) { //检测到版本低则更新 cstr.AppendLine("<fileRequest>").Append(fname).Append("</fileRequest>"); } ; } if (cstr.Length > 0) { Logger.SysLog(cstr.ToString(), "主记录"); Tcp.Send(cstr.ToString()); var fileEngine = new TransferFileEngine(TcpFiletransfer.TcpTransferEngine.Connections.Connection.EngineModel.AsClient, "1s68948k74.imwork.net", 30712); fileEngine.Connection.ConnectedToServer += (x, xxx) => { if (xxx.Success) { setting.LogInfo("连接到文件服务器", "主记录"); fileEngine.ReceiveFile(Environment.CurrentDirectory + "/setting"); } else { setting.LogInfo("请求文件失败:" + xxx.Info, "主记录"); } }; fileEngine.Receiver.ReceivingCompletedEvent += (x, xxx) => { if (xxx.Result == File_Transfer.Model.ReceiverFiles.ReceiveResult.Completed) { fileEngine.ReceiveFile(Environment.CurrentDirectory + "/setting"); } }; fileEngine.Connect(); } }
private static void TranslateFileStart() { Logger.SysLog("准备接收文件", "主记录"); var fileEngine = new TransferFileEngine(Connection.EngineModel.AsClient, TcpFileTubeIp, TcpFileTubePort); fileEngine.Connection.ConnectedToServer += (xs, xxx) => { if (xxx.Success) { setting.LogInfo("连接到文件服务器,准备开始接收文件", "主记录"); fileEngine.ReceiveFile(Environment.CurrentDirectory + "\\setting"); } else { setting.LogInfo("请求文件失败/结束:" + xxx.Info, "主记录"); } }; fileEngine.Receiver.ReceivingCompletedEvent += (xs, xxx) => { if (xxx.Result == File_Transfer.Model.ReceiverFiles.ReceiveResult.Completed) { setting.LogInfo("成功接收文件:" + xxx.Message + "(" + ++fileNowReceive + "/" + fileWaitToUpdate + ")"); if (fileNowReceive >= fileWaitToUpdate) { setting.LogInfo("文件已同步完成"); ServerResetConfig(); return; } fileEngine.ReceiveFile(Environment.CurrentDirectory + "/setting"); } else { setting.LogInfo(xxx.Title + ":" + xxx.Message); } }; fileEngine.Receiver.ReceivingStartedEvent += (xs, xxx) => { setting.LogInfo($"开始传输文件:{xxx.FileName}"); }; fileEngine.Connect(); }