Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 使用vbscript下载,某些文件不完整_File_Vbscript_Download - Fatal编程技术网

File 使用vbscript下载,某些文件不完整

File 使用vbscript下载,某些文件不完整,file,vbscript,download,File,Vbscript,Download,我正在使用以下vbscript自动从我的站点下载应用程序: HTTPDownload "bleh.com/hello.exe", "C:\" HTTPDownload "bleh.com/hello1.dll", "C:\" HTTPDownload "bleh.com/hello2.dll", "C:\" HTTPDownload "bleh.com/hello3.dll", "C:\" Sub HTTPDownload( myURL, myPath ) Dim i, objFile

我正在使用以下vbscript自动从我的站点下载应用程序:

HTTPDownload "bleh.com/hello.exe", "C:\"
HTTPDownload "bleh.com/hello1.dll", "C:\"
HTTPDownload "bleh.com/hello2.dll", "C:\"
HTTPDownload "bleh.com/hello3.dll", "C:\"

Sub HTTPDownload( myURL, myPath )
    Dim i, objFile, objFSO, objHTTP, strFile, strMsg
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    If objFSO.FolderExists( myPath ) Then
        strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
    ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
        strFile = myPath
    Else
        Exit Sub
    End If
    Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )
    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
    objHTTP.Open "GET", myURL, False
    objHTTP.Send
    For i = 1 To LenB( objHTTP.ResponseBody )
        objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
    Next
    objFile.Close( )
End Sub
奇怪的是,当我运行脚本时,2/4的文件被完全下载。其他文件中的一个只有2 KB(应为180 KB),另一个为0 KB(200 KB)

我在ftp服务器上仔细检查了一遍,存储的文件都是100%完整的,通过浏览器手动下载也可以

为什么我的脚本无法完全下载所有四个文件?

尝试使用,而不是使用,并使用保存(二进制)文件:


请求状态可能会为您提供一些有关问题的提示。还请检查服务器日志(如果可能)。

在Windows 8中,当我尝试写入文件时,会看到“写入文件失败”。虽然我是管理员,但它不是受保护的目录。该文件是否已经存在?如果是这样,您需要使用
stream.SaveToFile路径,2
(请参阅)。
Sub HTTPDownload(url, path)
  Set req = CreateObject("Msxml2.XMLHTTP.6.0")
  req.open "GET", url, False
  req.send

  If req.Status = 200 Then
    Set stream = CreateObject("ADODB.Stream")
    stream.Open
    stream.Type = 1 'binary
    stream.Write req.responseBody
    stream.SaveToFile path
    stream.Close
  Else
    WScript.Echo req.status & " " & req.statusText
  End If
End Sub