Подтвердить что ты не робот

Загрузите файл с VBS

У меня есть сценарий VBS, который генерирует URL для загрузки файла с сервера в моей сети. Теперь мне нужно загрузить файл в "C:\rWallpaper\wallpaper.png", URL хранится в переменной "url".

Мне бы хотелось, чтобы это работало в Linux как wget, просто скачайте и сохраните файл в указанном месте.

4b9b3361

Ответ 1

Вы можете скачать с помощью XMLHTTP и использовать поток ADO для записи двоичных данных;

dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "http://example.com/someimage.png", False
xHttp.Send

with bStrm
    .type = 1 '//binary
    .open
    .write xHttp.responseBody
    .savetofile "c:\temp\someimage.png", 2 '//overwrite
end with

Ответ 2

В приведенном выше ответе была выбрана ошибка Write to file failed. Code: 800A0BBC для меня, однако это сработало:

 HTTPDownload http://www.emagcloud.com/europeansealing/FSA_ESA_Compression_Packing_Technical_Manual_v3/pubData/source/images/pages/page10.jpg", "C:\"

Где

Sub HTTPDownload( myURL, myPath )
' This Sub downloads the FILE specified in myURL to the path specified in myPath.
'
' myURL must always end with a file name
' myPath may be a directory or a file name; in either case the directory must exist
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
'
' Based on a script found on the Thai Visa forum
' http://www.thaivisa.com/forum/index.php?showtopic=21832

    ' Standard housekeeping
    Dim i, objFile, objFSO, objHTTP, strFile, strMsg
    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    ' Create a File System Object
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )

    ' Check if the specified target file or folder exists,
    ' and build the fully qualified path of the target file
    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
        WScript.Echo "ERROR: Target folder not found."
        Exit Sub
    End If

    ' Create or open the target file
    Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )

    ' Create an HTTP object
    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

    ' Download the specified URL
    objHTTP.Open "GET", myURL, False
    objHTTP.Send

    ' Write the downloaded byte stream to the target file
    For i = 1 To LenB( objHTTP.ResponseBody )
        objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
    Next

    ' Close the target file
    objFile.Close( )
End Sub

Ответ 3

В дополнение к ответу Alex K я использовал следующее, если это кому-то помогает:

Определить объект

Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")

Звонок Скачать ссылку с файлом (изображение в нашем случае)

URL = "https://www.grupya.com/public/assets/img/logo.png"
objWinHttp.open "GET", URL, False
objWinHttp.send ""

Сохранить двоичные данные на диск

SaveBinaryData "c:\temp\my.png",objWinHttp.responseBody

Функция SaveBinaryData​​strong >

Function SaveBinaryData(FileName, Data)

' adTypeText for binary = 1
Const adTypeText = 1
Const adSaveCreateOverWrite = 2

' Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

' Specify stream type - we want To save Data/string data.
BinaryStream.Type = adTypeText

' Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write Data

' Save binary data To disk
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite

End Function

Ответ 4

Этот пост старый, но ошибка в первом ответе кода состоит в том, что вам нужны привилегии для записи в C:\, попробуйте на рабочем столе или %temp%, это работает.

Ответ 5

Попробуйте:

CreateObject("WScript.Shell").Run "curl -o "Path and filename"