Announcement

Collapse
No announcement yet.

how can I download files from https

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how can I download files from https

    Hi

    I have an vbscript which download files from http but I am unable to download it from https:

    Here is the script I am posting... can you help me to download the file from HTTPS?

    Code:
    'Script to download file from http
    
    Dim LogFile, argURL, argPath, countArgs
    LogFile = "Downloader" & "_" & Month(Now) & Day(Now) & Year(Now) & "_" & Hour(Now) & Minute(Now) & Second(Now) & ".txt"
    Set countArgs = WScript.Arguments.Count
    
    Set objArgs = WScript.Arguments
    LogInfo "No of arguments: " & countArgs, LogFile
    Wscript.Sleep 100
    
    If (countArgs > 2 Or countArgs < 2) Then
        LogInfo "Invalid no of arguments - Exiting the downloader", LogFile
        WScript.Echo "Invalid no of arguments, use downloader.vbs Url savePath"
        Wscript.Sleep 100
        Wscript.Quit
    Else
        argURL = objArgs(0) ' First argument URL
        argPath = objArgs(1) ' Second argument Path
        LogInfo "Arguments: "&argURL & "," & argPath, LogFile
    End If
    argURL = objArgs(0) ' First argument URL
    argPath = objArgs(1) ' Second argument Path
    
    LogInfo "Calling methond HTTPDownload(URL, Path), to download configurator " &argURL & "," & argPath, LogFile
    HTTPDownload argURL, argPath
    
    
    '****************************************************************************************************************
    'HTTP Downloader Function, accepts parameter of URL and the path to same configurator
    '****************************************************************************************************************
    Sub HTTPDownload(ConfiguratorURL, LocalPath)
        strFileURL = ConfiguratorURL
        strHDLocation = LocalPath
        
        LogInfo "Creating object MSXML2.XMLHTTP.", LogFile
    ' Fetch the file
        Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
        LogInfo "Object MSXML2.XMLHTTP created successfuly", LogFile
        
        objXMLHTTP.open "GET", strFileURL, falsew
        objXMLHTTP.send()
        
        If (Err.Number = 0) Then
            LogInfo "Sent URL request to MSXML2.XMLHTTP using HTTP GET", LogFile
        Else
            LogInfo "ERROR: " & Err.Description, LogFile
            Err.Clear
        End If    
        
    ' Creating ADODB.Stream object to save downloaded file in destination location
    LogInfo "Checking MSXML2.XMLHTTP Status", LogFile
    If objXMLHTTP.Status = 200 Then Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 'TypeBinary
        
        If (Err.Number = 0) Then
            LogInfo "MSXML2.XMLHTTP status: OK, ADODB.Stream object created successfully", LogFile
        Else
            LogInfo "ERROR: " & Err.Description, LogFile
            Err.Clear
        End If    
    
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    'Set the stream position to the start
    LogInfo "Setting stream position to 0 (Start)", LogFile
    
    LogInfo "Checking for existing Configurator...", LogFile
    Set objFSO = Createobject("Scripting.FileSystemObject")
    If objFSO.Fileexists(strHDLocation) Then 
    
        LogInfo "Duplicate configurator found." & strHDLocation, LogFile
        objFSO.DeleteFile strHDLocation
    
        If Err.Number = 0 Then 
            LogInfo strHDLocation & " -Deleted successfully..", LogFile
        Else
            LogInfo strHDLocation & " -unable to delete, Error: " & Err.Description, LogFile
            Err.Clear
        End If 
        
    Set objFSO = Nothing
    End if
    
    LogInfo strFileURL & " Saving @ "& strHDLocation, LogFile
    objADOStream.SaveToFile strHDLocation
    objADOStream.Close
    Set objADOStream = Nothing
        If Err.Number = 0 Then 
                LogInfo "Configurator download was successful @ " & strHDLocation, LogFile
            Else
                LogInfo "Configurator download Errorr: " & Err.Description, LogFile
                Err.Clear
        End If 
    
    Set objXMLHTTP = Nothing
    
    End Sub
    '*****************************************************************************************************************
    'HTTP Downloader Function, accepts parameter of URL and the path to same configurator
    '*****************************************************************************************************************
    
    
    
    '******************************************************************************************************************
    'Trace log method to log each steps of scripts
    '******************************************************************************************************************
    'Info/Error Tracer. It will take input for Log message and Log file Name
    Function LogInfo(Message, fileName)
        Set objFile = CreateObject("Scripting.FileSystemObject")
        'Open file in apppend mode 
        Set objTextFile = objFile.OpenTextFile(fileName, 8, True)
        'Writting message into log file along with date and time
        objTextFile.WriteLine ("[" & Now & "] " & message)
        objTextFile.Close
    End Function
    '**************************************************************************************************
    'Trace log method to log each steps of scripts
    '**************************************************************************************************
    Last edited by Rems; 1st October 2010, 21:20.

  • #2
    Re: how can I download files from https

    This forum is for SUGGESTIONS. Your post will be moved to a scripting forum in due course
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: how can I download files from https

      What is the error message?
      What version of IE is installed on the computer.

      Can you show one of the https urls?


      \Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: how can I download files from https

        does this help ?
        http://support.microsoft.com/kb/304420

        the exxecution of your script would probably be classed as "from a non-secure site"
        Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

        Comment

        Working...
        X