/// <summary> /// 判断文件是否发生变化,若变化则copy文件 /// </summary> /// <param name="config"></param> /// <param name="epi"></param> public void SSHCopy(Config config, ErrorPathInfo epi) { //获取mac端信息 MonitorServerDAL msd = new MonitorServerDAL(); MonitorServer ms = msd.GetMonitorServer(config, epi); if (ms == null) { Common.Util.LogManager.WriteLog(LogFile.Warning, "there is no MonitorServer that meet the conditions !"); return; } SFTPProxy sftpProxy = null; var sshlog = new Common.Util.SSHLogManager(); try { sftpProxy = new SFTPProxy(ms.monitorServerIP, ms.account, ms.password); #region 处理 foreach (ErrorEntry ee in epi.PathList) { string macPath = string.Empty; try { //获取mac路径 macPath = MacPathConvert(epi.source, ee.Path, ms.monitorMacPath, ms.startFile); //获取远端文件属性 SftpFile sf = sftpProxy.GetFileInfo(macPath); if (!ErrorPathFilter.IsUpdate(config, sf, ms)) { continue; } if (sf.IsDirectory) { #region 除job端已经删除的文件 #endregion foreach (SftpFile sfile in sftpProxy.Ls(sf)) { #region 过滤无关文件 if (String.Compare(sfile.Name.Trim('\r'), ".DS_Store", true) == 0 || String.Compare(sfile.Name.Trim('\r'), ".com.apple.timemachine.supported", true) == 0 || String.Compare(sfile.Name.Trim('\r'), "Icon", true) == 0) { continue; } #endregion if (!ErrorPathFilter.IsUpdate(config, sfile, ms)) { continue; } SSHCopyFile(sfile, ms, config.Path.OutputPath, sftpProxy); } } else { SSHCopyFile(sf, ms, config.Path.OutputPath, sftpProxy); } } catch (System.Exception ex) { Common.Util.LogManager.WriteLog(LogFile.Error, MessageUtil.GetExceptionMsg(ex, "")); sshlog.WriteLog(new Common.Util.SSHLog() { DateTime = DateTime.Now, LogType = Common.Util.SSHLogType.Failure, Message = ee.Path }); } } #endregion } catch (System.Exception ex) { Common.Util.LogManager.WriteLog(LogFile.Error, MessageUtil.GetExceptionMsg(ex, "")); } finally { if (sftpProxy != null) { sftpProxy.Close(); } } }