前端转vue
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoggerFTP.cs 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //
  6. using System.IO;
  7. using System.Net;
  8. using System.Text.RegularExpressions;
  9. using TellerSystem.ServiceProxy.Ext.ServiceHelper;
  10. using Platform.Common.RunningParameters;
  11. namespace TellerSystem.Library.Ext.TradeExtension
  12. {
  13. /// <summary>
  14. /// FTP日志上传备份
  15. /// </summary>
  16. /// <author>翟国栋</author>
  17. /// <date>2013/9/25 9:23:56</date>
  18. public static class LoggerFTP
  19. {
  20. static string FileName = "Logs";
  21. private static byte[] fileData = null;
  22. private static string filePath = "";
  23. private static List<string> localLogPath = new List<string>();
  24. /// <summary>
  25. /// 判断当前日志文件是否存在没有备份的
  26. /// </summary>
  27. /// <param name="file">文件路径</param>
  28. /// <param name="currentDate">营业日期</param>
  29. /// <returns>True-存在,False-不存在</returns>
  30. public static bool IsExistLogFile(FileSystemInfo file, string currentDate)
  31. {
  32. if (!file.Exists)
  33. return false;
  34. DirectoryInfo dire = file as DirectoryInfo;
  35. if (dire == null)
  36. return false;
  37. FileSystemInfo[] files = dire.GetFileSystemInfos();
  38. var fileCount = files.TakeWhile(x => Convert.ToDecimal(x.Name) < Convert.ToDecimal(currentDate)).ToList();
  39. if (fileCount.Count() > 0)
  40. return true;
  41. return false;
  42. }
  43. /// <summary>
  44. /// 递归遍历本地日志路径
  45. /// </summary>
  46. /// <param name="path">本地日志路径</param>
  47. /// <returns>日志路径列表</returns>
  48. private static List<string> getFiles(string path)
  49. {
  50. string[] strFileNames = Directory.GetFiles(path);
  51. string[] strDirectories = Directory.GetDirectories(path);
  52. foreach (string filename in strFileNames)
  53. {
  54. localLogPath.Add(filename);
  55. }
  56. foreach (string dir in strDirectories)
  57. {
  58. getFiles(dir);
  59. }
  60. return localLogPath;
  61. }
  62. /// <summary>
  63. /// 遍历子目录,备份当前日期前的日志文件
  64. /// </summary>
  65. /// <param name="file"></param>
  66. public static void GetFileSystemInfos(FileSystemInfo file)
  67. {
  68. localLogPath.Clear();
  69. if (!file.Exists) return;
  70. var list = getFiles(file.FullName);
  71. foreach (var item in list)
  72. {
  73. if (!item.Contains(LoginUserInfo.TradeDate))
  74. {
  75. var upLastName = item.Substring(item.IndexOf(FileName), item.Length - item.IndexOf(FileName)).ToString();
  76. //上传日志文件
  77. string upPath = string.Empty;
  78. string[] upPathArray = upLastName.Split('\\');
  79. for (int i = 0; i < upPathArray.Length; i++)
  80. {
  81. if (i < upPathArray.Length - 1)
  82. {
  83. upPath += upPathArray[i] + "/";
  84. }
  85. }
  86. fileData = File.ReadAllBytes(item);
  87. var result = 0.00;
  88. try
  89. {
  90. result = TradeHandle.FtpUpLoad(upLastName.Split('\\').LastOrDefault(), upPath, fileData);
  91. }
  92. catch (Exception e)
  93. {
  94. }
  95. }
  96. }
  97. }
  98. /// <summary>
  99. /// 清除本地日志文件
  100. /// </summary>
  101. public static void ClearFiles(FileSystemInfo file)
  102. {
  103. DirectoryInfo dire = file as DirectoryInfo;
  104. if (dire == null) return;
  105. FileSystemInfo[] files = dire.GetFileSystemInfos();
  106. string date = string.Empty;
  107. if (LoginUserInfo.TradeDate.Length == 8)
  108. date = LoginUserInfo.TradeDate.Substring(0, 4) + "-" + LoginUserInfo.TradeDate.Substring(4, 2) + "-" + LoginUserInfo.TradeDate.Substring(6, 2);
  109. DateTime dt = DateTime.Now;
  110. if (!DateTime.TryParse(date, out dt))
  111. return;
  112. string[] dateList = new string[3];
  113. dateList[0] = LoginUserInfo.TradeDate;
  114. dateList[1] = string.Format("{0:yyyyMMdd}", dt.AddDays(-1));
  115. dateList[2] = string.Format("{0:yyyyMMdd}", dt.AddDays(-2));
  116. for (int i = 0; i < files.Length; i++)
  117. {
  118. bool flag = true;
  119. string finame = files[i].Name;
  120. string fipath = files[i].FullName;
  121. for (int y = 0; y < dateList.Length; y++)
  122. {
  123. if (files[i].Name == dateList[y])
  124. {
  125. flag = false;
  126. continue;
  127. }
  128. }
  129. if (flag)
  130. {
  131. DirectoryInfo dirInfo = new DirectoryInfo(fipath);
  132. //删除目录及其子目录
  133. dirInfo.Delete(true);
  134. }
  135. }
  136. }
  137. }
  138. }