看代码网备份|利用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看代码的环境 ...
随机推荐
- elasticSearch6源码分析(3)cluster模块
1. cluser概述 One of the main roles of the master is to decide which shards to allocate to which nodes ...
- 状态压缩·一(状态压缩DP)
描述 小Hi和小Ho在兑换到了喜欢的奖品之后,便继续起了他们的美国之行,思来想去,他们决定乘坐火车前往下一座城市——那座城市即将举行美食节! 但是不幸的是,小Hi和小Ho并没有能够买到很好的火车票—— ...
- Netty 接受请求过程源码分析 (基于4.1.23)
前言 在前文中,我们分析了服务器是如何启动的.而服务器启动后肯定是要接受客户端请求并返回客户端想要的信息的,否则要你服务器干啥子呢?所以,我们今天就分析分析 Netty 在启动之后是如何接受客户端请求 ...
- c++/c 获取cpp文件行号跟文件名
编译器内置宏: 先介绍几个编译器内置的宏定义,这些宏定义不仅可以帮助我们完成跨平台的源码编写,灵活使用也可以巧妙地帮我们输出非常有用的调试信息. ANSI C标准中有几个标准预定义宏(也是常用的): ...
- Oracle中如何写存储过程
>存储过程是什么? 存储过程是一种命名的PL/SQL程序块,输入.输出参数数量[0个或多个],通常没有返回值[也有特殊的情况]. 运行SQL语句时,Oracle是要先编译再执行的:而存储过程是已 ...
- uni-app初体验及打包成apk
首先用HBuilderX新建建一个uni-app项目 新建一个目录ucenter,该目录下新建两个vue文件ucenter.vue和setting.vue ucenter.vue <templa ...
- TCP/IP 基础简介
引言本篇属于TCP/IP协议的基础知识,重点介绍了TCP/IP协议簇的内容.作用以及TCP.UDP.IP三种常见网络协议相关的基础知识. 内容TCP/IP协议簇是由OSI七层模型发展而来的,之所以存在 ...
- position sticky的兼容
position的sticky这个属性一般用于导航条,因为他在屏幕范围(viewport)时该元素的位置并不受到定位影响(设置是top.left等属性无效),当该元素的位置将要移出偏移范围时,定位又会 ...
- Node.js-串行化流程控制
内容主要来源:吴海星译,<Node.js实战>. 串行任务:需要一个接着一个坐的任务叫做串行任务. 可以使用回调的方式让几个异步任务按顺序执行,但如果任务过多,必须组织一下,否则过多的回调 ...
- 一张图看懂Mysql的join连接
INNER JOIN:当两个表中都匹配时返回行. LEFT JOIN:返回左表中的所有行,即使右表中没有匹配项也是如此. RIGHT JOIN:返回右表中的所有行,即使左表中没有匹配项也是如此. FU ...


