栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

用EasyWebSever实现文件上传

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用EasyWebSever实现文件上传

linux用busybox里边的httpd可以加一个简单脚本实现上传,可以说是最小巧的http服务器了。windows里边可以用hfs,但是感觉还是有时候反应慢,显臃肿。后来发现一个更小的http服务器EasyWebSever,60多kb,支持cgi,php之类的。当然也可以用python,nodejs做简单的绿色服务器,但还是麻烦些。EasyWebSever实现上传可以加php,但是下载php就几十兆,也可以加python,nodejs,都是需要的东西太大。

所以我想用js脚本去实现,解释程序windows自带,用个1k的脚本就行了。鼓捣半天发现js不支持二进制,最后没办法,改成了autoit3脚本。脚本参考的httpd_post_upload.cgi « networking - busybox - BusyBox: The Swiss Army Knife of Embedded Linux

EasyWebSever服务器设置映射--扩展名au3,执行程序“D:PCAPPSautoit3AutoIt3.exe d:tmp1.au3”,就是用1.au3当解释程序。用autoit3.exe当解释程序的话,因为服务器调用时不直接传递参数 ,而是靠环境变量传递,所以不能用。

index.htm的代码:


 
 


 File to upload:
 

---------------------------------------------------------------------------------------------------------------------------------

1.au3的代码:

ConsoleWrite(Binary("0x0a0d0a0d"))
$script_name=EnvGet("script_NAME")
$oexec=run("D:PCAPPSautoit3autoit3   d:tmp" & $script_name,@WorkingDir, @SW_HIDE, 7)

$aa=Binary("")
while 1
 $cc = ConsoleRead(0,1)
    If @error Then ExitLoop
    $aa=$aa & $cc
WEnd

StdinWrite($oexec,BinaryLen($aa) & chr(13))
StdinWrite($oexec,$aa )

$bb=Binary("")
while 1
 $cc = StdoutRead($oexec,0,1)
    If @error Then ExitLoop
    $bb=$bb & $cc
WEnd

ConsoleWrite($bb)

--------------------------------------------------------------------------------------------------------------------------------

2.au3的代码:

$aa=Binary("")
$count=0
$countok=0
$ii=0
while 1
 $cc = ConsoleRead(0,1)
    If @error Then ExitLoop    
    if @extended >0 then
       $aa=$aa & $cc
       $count=$count+@extended
       if  $count>20  then
            if  $countok=0 then
                $tt=BinaryMid($aa,1,20)
                $ttt=BinaryToString($tt)
                $ii=StringInStr($ttt,chr(13))
    $ccc=StringLeft($ttt,$ii)
                $countok=1
            endif
            if  $count>=$ccc+$ii Then ExitLoop
       endif
    endif
WEnd

for $i=$ii+1 to 2000
  if  BinaryMid($aa,$i,1)= chr(13) Then ExitLoop
next
$fengexian=BinaryMid($aa,$ii+1,$i-$ii-1)
for $iii=$i+1 to 2000
  if  BinaryMid($aa,$iii,2)= chr(10) & chr(13) Then ExitLoop
next

$ff=FileOpen("tmp",2)
FileWrite($ff,BinaryMid($aa,$iii+3,BinaryLen($aa)-$iii-3-BinaryLen($fengexian)-5))
FileClose($ff)

$dd=BinaryMid($aa,BinaryLen($aa)-BinaryLen($fengexian)-3,BinaryLen($fengexian))
if $fengexian = $dd  then 
ConsoleWrite("ok")
else
ConsoleWrite("err")
endif

-------------------------------------------------------------------------------------------------------------------------

最后我把js的代码也列出来,1.js:

var WshShell = Wscript.CreateObject("Wscript.Shell");
var WshSysEnv = WshShell.Environment("PROCESS");
script_name=WshSysEnv("script_NAME")

oexec=WshShell.exec("cscript /nologo d:\tmp\"+script_name)

aa=Wscript.StdIn.readall()


Wscript.StdOut.Write("rn")
Wscript.StdOut.Write("rn")


oexec.StdIn.Write(aa.length+"n")
oexec.StdIn.Write(aa );
Wscript.StdOut.Write(oexec.StdOut.readall())
------------------------------------------------------------------------------------------------------------------------------

2.js

count=Wscript.StdIn.readLine()  //如果不用count计数,程序会一直阻塞,因为不能确定管道的终点
fengexian=Wscript.StdIn.readLine()
count-=fengexian.length+2    //如果浏览器发送的换行是一个字符,程序会出问题

while (true){
bb=Wscript.StdIn.readLine()
count-=bb.length+2
if (bb=="rn" ||  bb=="")break;
}

aa=Wscript.StdIn.read(count-fengexian.length-6)
fso = new ActiveXObject("scripting.FileSystemObject")
f = fso.CreateTextFile("d:\tmp\tmp", true)
f.Write(aa);
f.Close();

Wscript.StdIn.read(2)
cc=Wscript.StdIn.read(fengexian.length)
if(fengexian==cc)Wscript.echo ("ok")
else Wscript.echo ("err")
 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/333701.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号