今天是上班第一天,服务器上的一个网站要搬到虚拟主机上,但是上传又太慢了。所以就写了个脚本,可以直接让虚拟主机从其它网站下载压缩包,然后再用虚拟主机自带的解压功能解压。将全部代码另存为tt.aspx,然后上传到空间根目录。再填上要下载的内容,比如http://www.163.com/Backup.RAR,再填上保存的虚拟主机所在的路径。注意是相对于tt.aspx的文件所在的路径。该脚本也可用在vps上。
<%@ Page Language=”C#” AutoEventWireup=”true” ValidateRequest=”false” %>
<%@ Import Namespace=”System.Collections.Generic” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>虚拟主机直接下载文件 by Tools@HKCAT.ORG </title>
<script language=”c#” runat=”server”>
protected void btadadd_Click(object sender, EventArgs e)
{
Server.ScriptTimeout = 99999;
string fName = TextBox1.Text.Trim();
string newName = TextBox2.Text.Trim();
System.Net.WebClient myWebClient = new System.Net.WebClient();
myWebClient.DownloadFile(fName, Server.MapPath(newName));
Response.Write(“下载完成…在线解压功能正在开发中…”);
}
</script>
</head>
<body>
<form id=”form1″ runat=”server”>
待上传文件地址:<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox><br />
新路径和名称:<asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox><br />
<asp:Button ID=”btadadd” runat=”server” CssClass=”button” Text=”上传” OnClick=”btadadd_Click” />
</form>
</body>
</html>
