Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Copy file from URL to folder

Hi All,

Can we copy a file into local machine from URL. I'm using below macro code to copy the files from source location to destination location.

Is it possible with instead of source local drive location can we place with URL. I tried placing the url in the variable "vImagesLocation" with "http://wvisusmjgwka8/vqdimages/" but didn't got success.

Share your ideas on this. Thanks in advance.

Sub CopyPasteImages

  Dim sOriginFolder, sDestinationFolder, sFile, oFSO

  Dim iCount, i

  Set oFSO = CreateObject("Scripting.FileSystemObject")

  Set vLensInspectionImageNames=ActiveDocument.Variables("vLensInspectionImageNames")

  Set vImageSourcePath=ActiveDocument.Variables("vImagesLocation")

  Set vImageDestinationPath=ActiveDocument.Variables("vImagesDestination")

  Set vSuffixImageName=ActiveDocument.Variables("vSuffixImageName")

  ArrFields = split(vLensInspectionImageNames.GetContent.String, ",")

  ArrFields2= Split(vSuffixImageName.GetContent.String,",")

' iCount = 0

  For Each fIndex in ArrFields

  sOriginFolder = vImageSourcePath.GetContent.string&fIndex  

        sDestinationFolder = vImageDestinationPath.GetContent.string&ArrFields2(i)&"-"&fIndex

  if oFSO.fileExists(sOriginFolder) then

' iCount = iCount + 1

  oFSO.CopyFile sOriginFolder, sDestinationFolder

  end if 

' If iCount >=500 then Exit Sub

  Next

End Sub

1 Solution

Accepted Solutions
jonasheisterkam
Partner - Creator III
Partner - Creator III

you can use wget for win and call it with execiute. Following macro i used, i think i found it in this community long time ago. Want you call it from the UI or from the skript? Much faster is robocopy if you can adress a unc and have a goot filter statement, robocopy has lots of options.

sub downloadaktuell

  

    strFileURL = "http://www.dwd.de/bvbw/generator/DWDWWW/Content/Oeffentlichkeit/KU/KU2/KU21/klimadaten/german/downlo..."

    strHDLocation = "C:\QlikView\Sonstiges\Wetter\aktuell.zip"

    Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

    objXMLHTTP.open "GET", strFileURL, false

    objXMLHTTP.send()

    If objXMLHTTP.Status = 200 Then

        Set objADOStream = CreateObject("ADODB.Stream")

        objADOStream.Open

        objADOStream.Type = 1

        objADOStream.Write objXMLHTTP.ResponseBody

        objADOStream.Position = 0

        Set objFSO = Createobject("Scripting.FileSystemObject")

        If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation

            Set objFSO = Nothing

            objADOStream.SaveToFile strHDLocation

            objADOStream.Close

            Set objADOStream = Nothing

        End if

        Set objXMLHTTP = Nothing

end sub

View solution in original post

6 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

I'm not a huge networking expert, but I think you can do it the following way:

1. Create a shared folder on your machine and give it a name.

2. Refer to it using the UNC convention:

\\<machine_name>\<share_name>

For example:

\\wvisusmjgwka8\vqdimages\

Notice that vqdimages is not just a folder, but a "Share name", the way you created it.

cheers,

Oleg Troyansky

Check out my book QlikView Your Business - now available to pre-order on Amazon!

jonasheisterkam
Partner - Creator III
Partner - Creator III

you can use wget for win and call it with execiute. Following macro i used, i think i found it in this community long time ago. Want you call it from the UI or from the skript? Much faster is robocopy if you can adress a unc and have a goot filter statement, robocopy has lots of options.

sub downloadaktuell

  

    strFileURL = "http://www.dwd.de/bvbw/generator/DWDWWW/Content/Oeffentlichkeit/KU/KU2/KU21/klimadaten/german/downlo..."

    strHDLocation = "C:\QlikView\Sonstiges\Wetter\aktuell.zip"

    Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

    objXMLHTTP.open "GET", strFileURL, false

    objXMLHTTP.send()

    If objXMLHTTP.Status = 200 Then

        Set objADOStream = CreateObject("ADODB.Stream")

        objADOStream.Open

        objADOStream.Type = 1

        objADOStream.Write objXMLHTTP.ResponseBody

        objADOStream.Position = 0

        Set objFSO = Createobject("Scripting.FileSystemObject")

        If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation

            Set objFSO = Nothing

            objADOStream.SaveToFile strHDLocation

            objADOStream.Close

            Set objADOStream = Nothing

        End if

        Set objXMLHTTP = Nothing

end sub

Not applicable
Author

Jonas, this is what i'm looking for. Thank you for sharing your ideas on this.

kamakshisuram
Creator
Creator

Hi Jonas,

I when I try to execute the macro , I am getting error   objXMLHTTP.open "GET", strFileURL, false as PErmissions denied. Can you please help me how to rectify this.

Capture.JPG

jonasheisterkam
Partner - Creator III
Partner - Creator III

Hi,

have you set the security lvl of the macro to allow external file actions? (under the Test button)

kamakshisuram
Creator
Creator

Hi Jonas,

It is working for me after I checked "Can Execute External Programs " under settings in Script editor.

Thanks for the response. I posted my application in Copy Multiple Files from SharePoint to Local

Regards,

Kamakshi Suram