Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URL encoding problem ?

Status
Not open for further replies.

crackoo

Programmer
Feb 17, 2011
132
TN
Hi !
I am trying to test a download of a mp3 file from this URL:
Code:
[URL unfurl="true"]http://promodj.com/download/4126268/Chris%20Parker%20-%20Life%20MIX%20%282011%20-%202013%29%20%28promodj.com%29.mp3[/URL]
but I encounter an Access Denied error at line No. 26, knowing that the url works in all browsers?
Can anyone here tell me what's my mistake ?
Code:
Option Explicit
Dim Titre,objFSO,Ws,objXMLHTTP,PathScript,Tab,URL,strHDLocation,objADOStream,Command,Start,File,ExempleURL
Titre = "Downloading MP3 by © Hackoo 2013"
Set objFSO = Createobject("Scripting.FileSystemObject")
PathScript = objFSO.GetParentFolderName(wscript.ScriptFullName) 'Chemin ou se localise le Vbscript
Set Ws = CreateObject("wscript.Shell")
ExempleURL = "[URL unfurl="true"]http://promodj.com/download/4126268/Chris%20Parker%20-%20Life%20MIX%20%282011%20-%202013%29%20%28promodj.com%29.mp3"[/URL]
URL = InputBox("Tapez ou collez l'URL dans le champ de saisie Exemple : "&Dblquote(ExempleURL)&"",Titre,ExempleURL)
URL = Escape(URL)
msgBox URL
If URL = "" Then WScript.Quit
Tab = split(url,"/")
File = Replace(Tab(UBound(Tab)),"28","")
File = Replace(Tab(UBound(Tab)),"29","")
File = Replace(Tab(UBound(Tab)),"20","")
File = Replace(Tab(UBound(Tab))," ","_")
File = Replace(Tab(UBound(Tab)),"-","_")
File = Replace(Tab(UBound(Tab)),"(","_")
File = Replace(Tab(UBound(Tab)),")","_")
File = Replace(Tab(UBound(Tab)),"%","_")
Msgbox  "The download of " & Dblquote(File) & " is in progress ! ",64,"The download of " & Dblquote(File) & " is in progress ! "
strHDLocation = PathScript & "\" & File
Set Ws = CreateObject("WScript.Shell")
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET",UnEscape(URL),false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
    Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 'adTypeBinary
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    'Set the stream position to the start
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
    objADOStream.SaveToFile strHDLocation
    objADOStream.Close
    Set objADOStream = Nothing
End If
Set objXMLHTTP = Nothing
 
MsgBox "The Download of " & Dblquote(Tab(UBound(Tab))) & " is finished ! ",64,"The Download of " & Dblquote(Tab(UBound(Tab))) & " is finished ! "
Command = "Cmd /c start explorer "& Dblquote(strHDLocation) &" "
Start = Ws.Run(Command,0,False)
 
Function Dblquote(str)
    Dblquote = chr(34) & str & chr(34)
End Function
 
Anyway, I don't think that File contains the expected value ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
What are the permissions of the file? In my example, which works, the file is 644.

Also, no sense in escaping the string only to unescape it unchanged. I also replaced Tab(UBound(Tab)) with File - otherwise you are just overwriting changes to the variable.

Code:
Option Explicit
Dim Titre,objFSO,Ws,objXMLHTTP,PathScript,Tab,URL,strHDLocation,objADOStream,Command,Start,File,ExempleURL
Titre = "Downloading MP3 by © Hackoo 2013"
Set objFSO = Createobject("Scripting.FileSystemObject")
PathScript = objFSO.GetParentFolderName(wscript.ScriptFullName) 'Chemin ou se localise le Vbscript
Set Ws = CreateObject("wscript.Shell")
'ExempleURL = "[URL unfurl="true"]http://promodj.com/download/4126268/Chris%20Parker%20-%20Life%20MIX%20%282011%20-%202013%29%20%28promodj.com%29.mp3"[/URL]
ExempleURL = "[URL unfurl="true"]http://nerdherd.cilverphox.com/music/Chicane/Easy%20To%20Assemble/05%20-%20Locking%20Down.mp3"[/URL]
URL = InputBox("Tapez ou collez l'URL dans le champ de saisie Exemple : "&Dblquote(ExempleURL)&"",Titre,ExempleURL)
'URL = Escape(URL)
'msgBox URL
'If URL = "" Then WScript.Quit
Tab = split(url,"/")
File =  Tab(UBound(Tab))
File = Replace(File,"%20"," ")
File = Replace(File,"%28","(")
File = Replace(File,"%29",")")
Msgbox  "The download of " & Dblquote(File) & " is in progress ! ",64,"The download of " & Dblquote(File) & " is in progress ! "
strHDLocation = PathScript & "\" & File
Set Ws = CreateObject("WScript.Shell")
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", URL, false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
    Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 'adTypeBinary
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    'Set the stream position to the start
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
    objADOStream.SaveToFile strHDLocation
    objADOStream.Close
    Set objADOStream = Nothing
End If
Set objXMLHTTP = Nothing
 
MsgBox "The Download of " & Dblquote(File) & " is finished ! ",64,"The Download of " & Dblquote(File) & " is finished ! "
Command = "Cmd /c start explorer "& Dblquote(strHDLocation) &" "
Start = Ws.Run(Command,0,False)
 
Function Dblquote(str)
    Dblquote = chr(34) & str & chr(34)
End Function

-Geates

 
Thank you Geates for your reply [2thumbsup]
The problem is resolved here in this discussion
Go, I wish you a Good Downloading [2thumbsup] and a good mixing
image.html


Code:
Option Explicit
Dim Titre,objFSO,Ws,objXMLHTTP,PathScript,Tab,URL,strHDLocation,objADOStream,Command,Start,File,ExempleURL
Titre = "Downloading MP3 by © Hackoo 2013"
Set objFSO = Createobject("Scripting.FileSystemObject")
PathScript = objFSO.GetParentFolderName(wscript.ScriptFullName) 'Chemin ou se localise le Vbscript
Set Ws = CreateObject("wscript.Shell")
ExempleURL = "[URL unfurl="true"]http://promodj.com/download/4126268/Chris%20Parker%20-%20Life%20MIX%20%282011%20-%202013%29%20%28promodj.com%29.mp3"[/URL]
'ExempleURL = "[URL unfurl="true"]http://nerdherd.cilverphox.com/music/Chicane/Easy%20To%20Assemble/05%20-%20Locking%20Down.mp3"[/URL]
URL = InputBox("Tapez ou collez l'URL dans le champ de saisie Exemple : "&Dblquote(ExempleURL)&"",Titre,ExempleURL)
'URL = Escape(URL)
msgBox URL
If URL = "" Then WScript.Quit
Tab = split(url,"/")
File =  Tab(UBound(Tab))
File = Replace(File,"%20"," ")
File = Replace(File,"%28","(")
File = Replace(File,"%29",")")
Msgbox  "The download of " & Dblquote(File) & " is in progress ! ",64,"The download of " & Dblquote(File) & " is in progress ! "
strHDLocation = PathScript & "\" & File
Set Ws = CreateObject("WScript.Shell")
'Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") ' ne marche pas avec MSXML2.XMLHTTP :(
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0") 'ça marche avec MSXML2.ServerXMLHTTP.3.0 :)

objXMLHTTP.open "GET", URL, false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
    Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 'adTypeBinary
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    'Set the stream position to the start
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
    objADOStream.SaveToFile strHDLocation
    objADOStream.Close
    Set objADOStream = Nothing
End If
Set objXMLHTTP = Nothing
 
MsgBox "The Download of " & Dblquote(File) & " is finished ! ",64,"The Download of " & Dblquote(File) & " is finished ! "
Command = "Cmd /c start explorer "& Dblquote(strHDLocation) &" "
Start = Ws.Run(Command,0,False)
 
Function Dblquote(str)
    Dblquote = chr(34) & str & chr(34)
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top