zoukankan      html  css  js  c++  java
  • 获取远程文件保存为本地文件(精简实用)

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <meta http-equiv="Content-Language" content="zh-CN" />
    <title>获取远程文件保存为本地文件</title>
    <style>
    #diva{text-align:center}
    #divb{padding:0px;border:1px dotted gray;500px}
    #divtitle{100%;text-align:center;font-weight:bold;background:silver;padding:8px;letter-spacing:5px}
    ul{list-style-type:none}
    ul li{margin-bottom:20px;}
    </style>
    </head>
    <body>

    <form action="?send=yes" method="post">
    <div id="diva">

     <div id="divb">
      <div  id="divtitle">获取远程文件保存为本地文件</div>

      <div style="text-align:left">
      <ul>
       <li>远程文件路径:<input type="text" size="40" value="http://" name="repath" onblur="zdf()"/></li>
       <li>本地路径:<input type="text" value="C:\" size="30" name="localpath" /></li>
       <li>本地保存的文件名:<input type="text" name="fname"/></li>
       <li style="font-size:9pt;color:red">说明:程序由QQ:155120699如果使用过程中发现问题请告知。远程文件路径请注意要写上文件名,本地路径可以写上文件名,也可以不写上文件名,如果不写上文件名,以远程的文件名命名。注意文件名均要带上扩展名</li>
       <li><br /><br /><input type="button" value="&nbsp;确定获取远程文件&nbsp;" onclick="sub()" /></li>
      </ul>
      </div>
     </div>

    </div>
    </form>

    <%
    if request.querystring("send")="yes" then

     dim repath '远程路径
     repath=request.form("repath")

     dim localpath '本地路径
     localpath=request.form("localpath")

     dim fname '本地保存的文件名
     fname=request.form("fname")

     set xx=server.createobject("microsoft.xmlhttp")

     xx.open "get",repath,False

     xx.send()

     set ado=server.createobject("adodb.stream")

     ado.type=1 '二进制模式

     ado.open

     ado.write xx.responsebody '把该二进流写入ado对象,注意xx.responsebody返回的是二进制流

     ado.savetofile localpath & fname,2  '2表示以替换方式保存文件

     response.write "<script>alert('远程获取文件成功!!保存的本地路径是:"&localpath &"\"& fname&"');window.location.href='?'</script>"

    end if
    %>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function zdf()
    {
     var spath=document.forms[0].repath.value;
     if(!/\/.+?\..{2,4}$/g.test(spath))
     {
      alert("远程路径填写错误!!请写个文件名。。如:[url]http://www.hezhiwu.cn/index.aspx[/url]");
     }
     else
     {
      var filename=spath.substring(spath.lastIndexOf("/")+1);
      //alert(filename);
      document.forms[0].fname.value=filename;

     }
    }

    function sub()
    {
     if(document.forms[0].fname.value=="")
     {
      alert("本地保存的文件名不能为空");
     }
     else
     {
      document.forms[0].submit();
     }
    }
    //-->
    </SCRIPT>
    </body></html>

  • 相关阅读:
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    linux tips
    vim more
    vim basic
    cut
    paste
    uniq
    Linux的用户
  • 原文地址:https://www.cnblogs.com/MaxIE/p/628617.html
Copyright © 2011-2022 走看看