//把文件从一个服务器拷到另一个服务器 private void getShareFile() { string sharefileSource = ConfigurationManager.AppSettings["sharefileSource"]; string sharefileTarget = ConfigurationManager.AppSettings["sharefileTarget"]; string ftpTarget = ConfigurationManager.AppSettings["FTPTarget"]; string strAdmin = ConfigurationManager.AppSettings["shareAdmin"]; string strPwd = ConfigurationManager.AppSettings["sharePwd"]; string strIP = ConfigurationManager.AppSettings["shareIP"]; string[] sAry = sharefileSource.Split('|'); string[] tAry = sharefileTarget.Split('|'); string[] fAry = ftpTarget.Split('|'); using (IdentityScope iss = new IdentityScope(strAdmin, strPwd, strIP)) { for (int i = 0; i < sAry.Length; i++) { DirectoryInfo TheFolder = new DirectoryInfo(sAry[i]); foreach (FileInfo FileItem in TheFolder.GetFiles()) { string str1 = DateTime.Now.ToString("yyyMMdd"); string str2 = DateTime.Now.AddDays(-1).ToString("yyyMMdd"); if (FileItem.Name.IndexOf(str1) > -1 || FileItem.Name.IndexOf(str2) > -1) { File.Copy(sAry[i] + FileItem.Name, tAry[i] + FileItem.Name, true); UploadFile(fAry[i], tAry[i] + FileItem.Name); //File.Delete(tempfilepath + FileItem.Name); writelog("成功同步文件:" + sAry[i] + FileItem.Name); } } } } }
/// <summary> /// 获取气象预报报文 /// </summary> private void getQxPacket() { string SourcePath = ConfigurationManager.AppSettings["PacketSource"]; string targetPath = ConfigurationManager.AppSettings["PacketTarget"]; string strAdmin = ConfigurationManager.AppSettings["shareAdmin"]; string strPwd = ConfigurationManager.AppSettings["sharePwd"]; string strIP = ConfigurationManager.AppSettings["shareIP"]; using (IdentityScope iss = new IdentityScope(strAdmin, strPwd, strIP)) { DirectoryInfo TheFolder = new DirectoryInfo(SourcePath); writelog("遍历文件夹:" + SourcePath); foreach (FileInfo FileItem in TheFolder.GetFiles()) { string str1 = DateTime.Now.ToString("yyyMMdd") + "224519"; string str2 = DateTime.Now.ToString("yyyMMdd") + "083019"; if (FileItem.Name.IndexOf(str1) > -1 || FileItem.Name.IndexOf(str2) > -1) { File.Copy(SourcePath + FileItem.Name, targetPath + FileItem.Name, true); ReadTXT(targetPath + FileItem.Name); writelog("成功同步文件:" + FileItem.Name); } } } }