看代码网备份|利用WebClient|eKing.CmdDownLoadDbBakOper|实现定时拷贝数据库备份文件到文件服务器
摘要:
DbLookDaiMaBak.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.IO;
public partial class DbLookDaiMaBak
:
System.Web.UI.Page
{
#region DateTimeGetByStrYyyyMMddHHmmss|yyyyMMddHHmmss转成时间
/// <summary>
/// yyyyMMddHHmmss转成时间
/// </summary>
/// <param name="str">时间格式字符串(要求14位长)|如:20180621020355
/// <returns>如果格式不正确,抛出异常|否则返回时间值|如:2018-06-21 02:03:55</returns>
public DateTime DateTimeGetByStrYyyyMMddHHmmss(string str)
{
if (str == null || str.Length == 0)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "str == null || str.Length == 0"
);
}
int iLen = str.Length;
if (iLen != 14)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "str.Length != 8"
);
}
string dateStr
=
str.Substring(0, 4)
+ "-" + str.Substring(4, 2)
+ "-" + str.Substring(6, 2)
+ " " + str.Substring(8, 2)
+ ":" + str.Substring(10, 2)
+ ":" + str.Substring(12, 2);
return DateTime.Parse(dateStr);
}
/// <summary>
/// yyyyMMddHHmmss转成时间
/// </summary>
/// <param name="str">时间格式字符串(要求14位长)|如:20180621020355
/// <param name="defaultValue">如果时间格式不正确,返回的时间默认值
/// <returns>如果格式不正确,返回默认值defaultValue|否则返回时间值|如:2018-06-21 02:03:55</returns>
public DateTime DateTimeGetByStrYyyyMMddHHmmss(string str, DateTime defaultValue)
{
if (str == null || str.Length == 0)
{
return defaultValue;
}
int iLen = str.Length;
if (iLen != 14)
{
return defaultValue;
}
string dateStr
=
str.Substring(0, 4)
+ "-" + str.Substring(4, 2)
+ "-" + str.Substring(6, 2)
+ " " + str.Substring(8, 2)
+ ":" + str.Substring(10, 2)
+ ":" + str.Substring(12, 2);
DateTime theResult = defaultValue;
if (DateTime.TryParse(dateStr, out theResult))
{
return theResult;
}
return defaultValue;
}
#endregion DateTimeGetByStrYyyyMMddHHmmss|yyyyMMddHHmmss转成时间
#region GetGB2312MD5|获得GB2312(中文编码)格式的MD5值
/// <summary>
/// 获得GB2312编码的MD5值
/// </summary>
/// <param name="s">需要MD5的字符串
/// <returns></returns>
public string GetGB2312MD5(string s)
{
if (s == null)
s = "";
MD5 md5 = new MD5CryptoServiceProvider();
System.Text.Encoding en = System.Text.Encoding.GetEncoding("GB2312");
byte[] t = md5.ComputeHash(en.GetBytes(s));
StringBuilder sb = new StringBuilder(32);
for (int i = 0; i < t.Length; i++)
{
sb.Append(t[i].ToString("x").PadLeft(2, '0'));
}
return sb.ToString();
}
#endregion GetGB2312MD5|获得GB2312编码的MD5值
/// <summary>
///
/// </summary>
/// <param name="callName">
/// <param name="dt">
/// <returns></returns>
protected string ToSign(string callName, string dt)
{
string str = callName + dt + "ekinglbs.lookdaima";
return GetGB2312MD5(str);
}
/// <summary>
/// 获得网站根目录(比如网站虚拟目录tools) - http://www.slowx.net/tools/
/// </summary>
/// <returns></returns>
public string GetWebRootUrl()
{
HttpContext hc = HttpContext.Current;
if (hc == null)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:HttpContext hc = HttpContext.Current值为null。"
);
}
// 虚拟目录加完整参数页面地址 //
// /SlowXWebSite/Test/WebCommon/Default.aspx?id=default.aspx&web=%cb%aa%d2%b6&dt=D%3a%5ccanoe%5cs.aspx&p=fdf%5cf%2ffds.fdsf%3ffdf //
string strPathAndQuery = hc.Request.Url.PathAndQuery;
// 完整URL地址 //
string strAbsoluteUri = hc.Request.Url.AbsoluteUri;
int idx = strAbsoluteUri.LastIndexOf(strPathAndQuery);
if (idx == -1)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "int idx = strAbsoluteUri[" + strAbsoluteUri + "].LastIndexOf(strPathAndQuery[" + strPathAndQuery + "]) == -1;"
);
}
string theResult = strAbsoluteUri.Substring(0, idx);
if (hc.Request.ApplicationPath == "/")
return theResult;
else
return theResult + hc.Request.ApplicationPath;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected string DataBindTheControls(bool isDebug)
{
if (isDebug)
{
string debugWebRootUrl = GetWebRootUrl();
if (debugWebRootUrl.EndsWith("/") || debugWebRootUrl.EndsWith("\\"))
{
debugWebRootUrl = debugWebRootUrl.Substring(0, debugWebRootUrl.Length - 1);
}
return "+" + debugWebRootUrl + "/debugdata.zip";
}
string noPower = "-鉴权失败:" + Request.Url.AbsoluteUri;
string callName = Request.QueryString["CallUserName"];
string dt = Request.QueryString["dt"];
string sign = Request.QueryString["sign"];
if (callName == null || callName.Length == 0)
return noPower + "[callName]";
if (dt == null || dt.Length == 0)
return noPower +"[dt]";
if (sign == null || sign.Length == 0)
{
return noPower + "[sign]";
}
DateTime dtValue = DateTimeGetByStrYyyyMMddHHmmss(dt, DateTime.MinValue);
if (dtValue == DateTime.MinValue)
{
return noPower + "[dt.MinValue]";
}
if (callName != "ekinglbs")
{
return noPower + "[callName=" + callName + "]";
}
string newSign = ToSign(callName, dt);
if (newSign != sign)
{
return noPower + "[callName=" + callName + "]" + "[dt=" + dt + "]" + "[sign=" + sign + "]" + "[newSign=" + newSign + "]";
}
string rootDir = Request.PhysicalApplicationPath + "LookDaiMaDB";
DirectoryInfo dir = new DirectoryInfo(rootDir);
if (!dir.Exists)
{
return "-目录" + dir.FullName + "不存在";
}
FileInfo[] fA = dir.GetFiles();
string webRootUrl = GetWebRootUrl();
if (webRootUrl.EndsWith("/") || webRootUrl.EndsWith("\\"))
{
webRootUrl = webRootUrl.Substring(0, webRootUrl.Length - 1);
}
foreach (FileInfo fi in fA)
{
if (fi == null)
continue;
if (fi.Extension == null)
continue;
if (fi.Extension.Trim().ToLower() != ".trn")
{
continue;
}
if (fi.LastWriteTime.Date != DateTime.Now.Date)
{
continue;
}
return "+" + webRootUrl + "/LookDaiMaDB/" + fi.Name;
}
return "-没有找到文件";
}
/// <summary>
/// 转换成要下载的文件路径
/// </summary>
/// <param name="sender">
/// <param name="e">
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentEncoding
=
System.Text.Encoding.GetEncoding("gb2312");
if (!this.IsPostBack)
{
try
{
string str = DataBindTheControls(false);
Response.Write(str);
}
catch (Exception err)
{
Response.Write("-系统异常:" + err.Message);
}
}
}
}
downdb.bat
C:\Cmds\CS\common\DownLoadDbBak\eKing.CmdDownLoadDbBakOper.exe EmailName=qq89616537 EmailSmtpServer=smtp.163.com EmailSend=qq89616537@163.com EmailPwd=[****密码隐藏***] EnableSsl=false EmailRecv=89616537@qq.com;qq89616537@163.com; EmailTitle={Oper}.{DateTime.Date}-看代码网数据库备份文件拷贝归档操作 EmailText=看代码网数据库备份文件拷贝归档操作 EmailEncoding=gb2312 HtmlFlag=false PwdTextType=des3 ConsoleWriteFlag=true DownLoadUrl="http://10.186.73.30:8088/DbLookDaiMaBak.aspx?" CallUserName=ekinglbs CallPwd=lookdaima CallPwdTextType=text DayLeft=5 SaveDir=C:\WebBackups\DBs\LookDaiMa SaveFileName=lookdaima.trn
看代码网备份|利用WebClient|eKing.CmdDownLoadDbBakOper|实现定时拷贝数据库备份文件到文件服务器的更多相关文章
- winform客户端利用webClient实现与Web服务端的数据传输
由于项目需要,最近研究了下WebClient的数据传输.关于WebClient介绍网上有很多详细介绍,大概就是利用WebClient可以实现对Internet资源的访问.无外乎客户端发送请求,服务端处 ...
- c#利用WebClient和WebRequest获取网页源代码的比较
前几天举例分析了用asp+xmlhttp获取网页源代码的方法,但c#中一般是可以利用WebClient类和WebRequest类获取网页源代码.下面分别说明这两种方法的实现. WebClient类获取 ...
- c#利用WebClient和WebRequest获取网页源代码
C#中一般是可以利用WebClient类和WebRequest类获取网页源代码.下面分别说明这两种方法的实现. WebClient类获取网页源代码 WebClient类 WebClient ...
- GuozhongCrawler看准网爬虫动态切换IP漫爬虫
有些关于URL去重的方面代码没有提供,须要自己去实现.主要这里提供思路 项目地址:http://git.oschina.net/woshidaniu/GuozhongCrawler/tree/mast ...
- 一个简单的利用 WebClient 异步下载的示例(三)
继续上一篇 一个简单的利用 WebClient 异步下载的示例(二) 后,继续优化它. 1. 直接贴代码了: DownloadEntry: public class DownloadEntry { p ...
- 一个简单的利用 WebClient 异步下载的示例(一)
继上一篇文章 一个简单的利用 HttpClient 异步下载的示例 ,我们知道不管是 HttpClient,还算 WebClient,都不建议每次调用都 new HttpClient,或 new We ...
- 1.JVM前奏篇(看官网怎么说)
JVM(Java Virtual Machine) 前奏篇(看官网规范怎么说) 1.The relation of JDK/JRE/JVM 在下图中,我们所接触的,最熟悉,也是经常打交道的 最顶层 J ...
- 看代码学知识之(2) ListView无数据时显示其他View
看代码学知识之(2) ListView无数据时显示其他View 今天看的一块布局是这样的: <!-- The frame layout is here since we will be show ...
- calltree看代码调用图
calltree是在linux下面看c代码(尤其是复杂的内核代码)的神器. 推荐 calltree+vim + ctags + cscope + taglist [ vim: 搭建vim看代码的环境 ...
随机推荐
- Nginx range filter模块数字错误漏洞修复 (Nginx平滑升级)
对线上生产环境服务器进行漏洞扫描, 发现有两台前置机器存在Nginx range filter模块数字错误漏洞, 当使用nginx标准模块时,攻击者可以通过发送包含恶意构造range域的header ...
- 【IT笔试面试题整理】堆栈和队列
如何准备: Whether you are asked to implement a simple stack / queue, or you are asked to implementa modi ...
- 【转】常见六大Web 安全攻防解析
原文转自:https://segmentfault.com/a/1190000018073845 作者:浪里行舟 在互联网时代,数据安全与个人隐私受到了前所未有的挑战,各种新奇的攻击技术层出不穷.如何 ...
- MyBatis空where拦截器
最近项目中出现了至少两次因为Mybatis的动态where条件不满足导致实际sql语句的where条件为空,进而查询全表,当数据量比较大的时候,导致OOM的情况. 如何禁止这种情况,个人觉得三种措施: ...
- Netty的基本概念
异步 等待它的同时你也可以做点别的事情 阻塞I/O 只能同时处理一个连接,要管理多个并发客户端,需要为每个新的客户端Socket创建一个新的Thread 使用Selector的非阻塞I/O class ...
- Activity正确获取View宽高
在View的measure完成后,一般可以通过getMeasureWidth/getMeasureWidth方法可以正确的获取View的宽高,而在特殊情况下,可能需要多次measure才能确定最终的测 ...
- HDU4845(SummerTrainingDay02-C 状态压缩bfs)
拯救大兵瑞恩 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- 背景平铺(兼容IE8)
标准浏览器通过background-size属性设置;IE8以下通过滤镜实现. 代码如下: /* IE8 */ filter: progid:DXImageTransform.Microsoft.Al ...
- @PathVariable与@RequestParam的区别
@PathVariable与@RequestParam的区别首先呢这二个注解都是接收参数使用的,下面来看一下它们的区别.@PathVariable注解@RequestMapping(value ={“ ...
- hihocoder [Offer收割]编程练习赛12 [1495] ---- 矩形分割
原题链接 矩形分割 算法分析: 解决该题要用到"并查集"的思想. 这里有一篇不错的博客介绍并查集: 并查集(Union-Find)算法介绍 记 int total=N*M,这里会有 ...


