下载地址:上传测试页面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
@echo off echo %time% call VIFP D https://api.snote.cn/guest/ ip.php FOR /f %%a IN (ip.php) DO ( echo 本机公网IP:%%a del /f /q ip.php ) echo %time% call VIFP U https://api.snote.cn/guest/index.php VIFP.zip echo 上传完成 echo %time% call VIFP P echo 输出完成 echo %time% pause |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
@echo off & set url=%2 if "%1"=="" (goto H) else (goto %1) :D (for /f "skip=50 tokens=* delims=" %%a in (%~f0) do (if "%%a"=="REM -" (goto :DE) else (echo;%%a)))>%tmp%\Down.vbs :DE start /wait %tmp%\Down.vbs "%url%%3" "%~f3" goto :eof REM - :U (for /f "skip=65 tokens=* delims=" %%a in (%~f0) do (if "%%a"=="REM -" (goto :UE) else (echo;%%a)))>%tmp%\upload.vbs :UE start /min /wait %tmp%\upload.vbs "%url%" "%~f3" goto :eof REM - :P (for /f "skip=195 tokens=* delims=" %%a in (%~f0) do (echo;%%a))>index.php goto :eof REM - :H mode con cols=80 lines=30 title VBS Interactive File Prototype echo, echo 文件上传或下载 echo, echo VIFP {#1[D,U,P,H]} {#2http://*/} {#3[drive:][path][filename]} echo, echo D 下载一个文件到本地。 echo - 例如: echo call VIFP D https://api.snote.cn/guest/ VIFP.zip echo 本地文件将会被覆盖。服务器不存在此文件,本地文件也会被擦除! echo, echo U 上传一个文件至服务器。 echo - 例如: echo call VIFP U https://api.snote.cn/guest/ VIFP.zip echo 服务器文件将被覆盖。创建或覆盖,及上传失败均不会有任何提示! echo, echo P 服务器POST接受文件 index.php 模板。 echo, echo H 显示本帮助页。 echo,&echo, echo 提醒:1.服务器上需先设置好接受POST文件。2.链接是区分大小写的! echo, echo #1 参数1 功能和帮助页的开关 (无需加“/”) echo #2 参数2 服务器,必须加上“http://”*“/” echo #3 参数3 本地文件路径,文件全名或完整路径 echo,&echo, echo VIFP 1.3 by ZhangZsky 2018/12/30 pause >nul goto :eof REM - Sub Download(url,target) Dim http,ado Set http = CreateObject("Msxml2.ServerXMLHTTP") http.SetOption 2,13056 http.open "GET",url,False http.send Set ado = CreateObject("Adodb.Stream") ado.Type = 1 ado.Open ado.Write http.responseBody ado.SaveToFile target,2 ado.Close End Sub Download WScript.Arguments(0),WScript.Arguments(1) REM - Class vbsFileUpload Public c_strDestURL ' 文件POST上传php链接 Public c_strFileName ' 要上传的本地文件路径 Public c_strFieldName ' 字段名,HTML表单Form中的input Public c_strBoundary ' 文件POST上传数据包中的分隔符 Public c_strContentType ' text/plain 或 image/pjpeg 此类 Public c_strResponseText ' 文件上传后,服务器返回的信息 Public c_boolPrepared ' 布尔值准备情况 Public c_strErrMsg ' 可能的错误信息 Public Function vbsUpload CheckRequirements() If c_boolPrepared Then UploadFile c_strDestURL, c_strFileName, c_strFieldName Else 'WScript.Echo c_strErrMsg End If End Function Private Function CheckRequirements Dim objFSO Set objFSO = CreateObject("Scripting.FileSystemObject") If Not objFSO.FileExists(c_strFileName) Then c_strErrMsg = c_strErrMsg & vbCrLf & "文件不存在.." Else On Error Resume Next CreateObject "MSXML2.XMLHTTP" If Not Err = 0 Then c_strErrMsg = c_strErrMsg & vbCrLf & Err.Descriptiof Else c_boolPrepared = True End If End If End Function Private Function UploadFile(DestURL, FileName, FieldName) Dim FileContents Dim FormData Dim Boundary Boundary = c_strBoundary FileContents = GetFile(FileName) FormData = BuildFormData(FileContents, Boundary, FileName, FieldName) WinHTTPPostRequest DestURL, FormData, Boundary End Function Private Function WinHTTPPostRequest(URL, FormData, Boundary) Dim xmlhttp Set xmlhttp = CreateObject("MSXML2.XMLHTTP") On Error Resume Next xmlhttp.Open "POST", URL, False xmlhttp.setRequestHeader "Content-Type", "multipart/form-data; boundary=" + Boundary xmlhttp.send FormData c_strResponseText = xmlhttp.responseText Set xmlhttp = Nothing End Function Private Function BuildFormData(FileContents, Boundary, FileName, FieldName) Dim FormData Dim Pre Dim Po Dim ContentType ContentType = c_strContentType Pre = "--" + Boundary + vbCrLf + mpFields(FieldName, FileName, ContentType) Po = vbCrLf + "--" + Boundary + "--" + vbCrLf Const adLongVarBinary = 205 Dim RS Set RS = CreateObject("ADODB.Recordset") RS.Fields.Append "b", adLongVarBinary, Len(Pre) + LenB(FileContents) + Len(Po) RS.Open RS.AddNew Dim LenData LenData = Len(Pre) RS("b").AppendChunk (StringToMB(Pre) & ChrB(0)) Pre = RS("b").GetChunk(LenData) RS("b") = "" LenData = Len(Po) RS("b").AppendChunk (StringToMB(Po) & ChrB(0)) Po = RS("b").GetChunk(LenData) RS("b") = "" RS("b").AppendChunk (Pre) RS("b").AppendChunk (FileContents) RS("b").AppendChunk (Po) RS.Update FormData = RS("b") RS.Close BuildFormData = FormData End Function Private Function StringToMB(S) Dim I Dim B For I = 1 To Len(S) B = B & ChrB(Asc(Mid(S, I, 1))) Next StringToMB = B End Function Private Function mpFields(FieldName, FileName, ContentType) Dim MPTemplate MPTemplate = "Content-Disposition: form-data; name=""{field}"";" + _ " filename=""{file}""" + vbCrLf + _ "Content-Type: {ct}" + vbCrLf + vbCrLf Dim Out Out = Replace(MPTemplate, "{field}", FieldName) Out = Replace(Out, "{file}", FileName) mpFields = Replace(Out, "{ct}", ContentType) End Function Private Function GetFile(FileName) Dim Stream Set Stream = CreateObject("ADODB.Stream") Stream.Type = 1 Stream.Open Stream.LoadFromFile FileName GetFile = Stream.Read Stream.Close End Function End Class Dim myUpload Set myUpload = New vbsFileUpload myUpload.c_strDestURL = WScript.Arguments(0) myUpload.c_strFileName = WScript.Arguments(1) myUpload.c_strFieldName = "file" myUpload.c_strContentType = "application/octet-stream" myUpload.vbsUpload() 'WScript.Echo myUpload.c_strResponseText 'WScript.Echo myUpload.c_strErrMsg Set myUpload = Nothing REM - <?php header("Content-Type: text/html;charset=utf-8"); $allowedExts = array("txt", "zip", "7z"); //后缀名限制 $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if ((($_FILES["file"]["type"] == "application/upload") || ($_FILES["file"]["type"] == "text/plain") || ($_FILES["file"]["type"] == "application/zip") || ($_FILES["file"]["type"] == "application/x-zip-compressed") || ($_FILES["file"]["type"] == "application/octet-stream")) //二进制上传,及上面的文件类型限制 && ($_FILES["file"]["size"] < 5242880) //文件大小限制 && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "错误:: " . $_FILES["file"]["error"] . "<br>"; } else { if (file_exists("guest/" . $_FILES["file"]["name"])) { echo " 文件已覆盖:" . $_FILES["file"]["name"]; move_uploaded_file($_FILES["file"]["tmp_name"], "guest/" . $_FILES["file"]["name"]); } else { echo " 文件已上传:" . $_FILES["file"]["name"]; move_uploaded_file($_FILES["file"]["tmp_name"], "guest/" . $_FILES["file"]["name"]); } } } else { echo "文件不符合"; } ?> |
发表回复