LapidusCreatorium Posted June 16, 2008 Share Posted June 16, 2008 Hello, I need some help if it is possible. I have this code $File1 = "http://URL_HERE.COM/download.aspx?id=9" ; Sets the location of file to be downloaded $FilePath = "c:\installation_path\program_updates\update.exe" InetGet($File1, $FilePath, 1, 0) ; Downloads File1 While @InetGetActive Sleep(15000) ; Sleeps while files download WEnd I need to know how can I retrieve the file name from $File1 url. he url redirects to an exe with different names, and I need the file to be downloaded with same file name as on the download server. I have no idea how can I do this.. Thanks for your help. Link to comment Share on other sites More sharing options...
weaponx Posted June 16, 2008 Share Posted June 16, 2008 (edited) Try this:$filename = HTTPFileName("http://www.someurl.com/getfile.php?id=666") MsgBox(0,"",$filename) Func HTTPFileName($sUrl) $oHTTP = ObjCreate('winhttp.winhttprequest.5.1') $oHTTP.Open('POST', $sUrl, 1) $oHTTP.SetRequestHeader('Content-Type','application/x-www-form-urlencoded') $oHTTP.Send() $oHTTP.WaitForResponse $ContentDisposition = $oHTTP.GetResponseHeader("Content-Disposition:filename") ;ConsoleWrite($ContentDisposition & @CRLF) $array = StringRegExp($ContentDisposition, 'filename="(.*)"',3) ;ConsoleWrite($array[0] & @CRLF) ;ConsoleWrite($oHTTP.GetAllResponseHeaders()) Return $array[0] EndFuncHere is the original version I posted:#525259 Edited June 16, 2008 by weaponx Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted June 16, 2008 Author Share Posted June 16, 2008 Try this: $filename = HTTPFileName("http://www.someurl.com/getfile.php?id=666") MsgBox(0,"",$filename) Func HTTPFileName($sUrl) $oHTTP = ObjCreate('winhttp.winhttprequest.5.1') $oHTTP.Open('POST', $sUrl, 1) $oHTTP.SetRequestHeader('Content-Type','application/x-www-form-urlencoded') $oHTTP.Send() $oHTTP.WaitForResponse $ContentDisposition = $oHTTP.GetResponseHeader("Content-Disposition:filename") ;ConsoleWrite($ContentDisposition & @CRLF) $array = StringRegExp($ContentDisposition, 'filename="(.*)"',3) ;ConsoleWrite($array[0] & @CRLF) ;ConsoleWrite($oHTTP.GetAllResponseHeaders()) Return $array[0] EndFunc Here is the original version I posted: #525259 Thanks for reply. But I get this error: (10) : ==> The requested action with this object has failed.: $ContentDisposition = $oHTTP.GetResponseHeader("Content-Disposition:filename") $ContentDisposition = $oHTTP.GetResponseHeader("Content-Disposition:filename")^ ERROR Link to comment Share on other sites More sharing options...
weaponx Posted June 16, 2008 Share Posted June 16, 2008 $filename = HTTPFileName("http://www.someurl.com/getfile.php?id=666") MsgBox(0,"",$filename) Func HTTPFileName($sUrl) $oHTTP = ObjCreate('winhttp.winhttprequest.5.1') $oHTTP.Open('POST', $sUrl, 1) $oHTTP.SetRequestHeader('Content-Type','application/x-www-form-urlencoded') $oHTTP.Send() $oHTTP.WaitForResponse $ContentDisposition = StringRegExp($oHTTP.GetResponseHeader("Content-Disposition"), 'filename="(.*)"',3) Return $ContentDisposition[0] EndFunc Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted June 16, 2008 Author Share Posted June 16, 2008 Thank you. Sorry for bugging you but i am still getting an error: download test.au3 (11) : ==> The requested action with this object has failed.: $ContentDisposition = StringRegExp($oHTTP.GetResponseHeader("Content-Disposition"), 'filename="(.*)"',3) $ContentDisposition = StringRegExp($oHTTP.GetResponseHeader("Content-Disposition")^ ERROR what am I doing wrong? Link to comment Share on other sites More sharing options...
weaponx Posted June 16, 2008 Share Posted June 16, 2008 Thank you. Sorry for bugging you but i am still getting an error: download test.au3 (11) : ==> The requested action with this object has failed.: $ContentDisposition = StringRegExp($oHTTP.GetResponseHeader("Content-Disposition"), 'filename="(.*)"',3) $ContentDisposition = StringRegExp($oHTTP.GetResponseHeader("Content-Disposition")^ ERROR what am I doing wrong? You should have just taken a look at the link I posted, I know it works. Just change the url. This will dump all of the headers to the SciTe console. $oHTTP = ObjCreate('winhttp.winhttprequest.5.1') $oHTTP.Open('POST', 'http://www.shsforums.net/index.php?automodule=downloads&req=download&code=confirm_download&id=141', 1) $oHTTP.SetRequestHeader('Content-Type','application/x-www-form-urlencoded') ;$oHTTP.setTimeouts(5000, 5000, 15000, 15000) $oHTTP.Send() $oHTTP.WaitForResponse $ContentDisposition = $oHTTP.GetResponseHeader("Content-Disposition") $array = StringRegExp($ContentDisposition, 'filename="(.*)"',3) ConsoleWrite("Filename: " & $array[0] & @CRLF) ConsoleWrite($oHTTP.GetAllResponseHeaders()) Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted June 16, 2008 Author Share Posted June 16, 2008 Yes, it is working for URL http://www.shsforums.net/index.php?automod...load&id=141But not from my URL.When I put my URL I get the above errors.It's very very very weird.I tested with a php header redirection and I get those errors.I do not understand why it is working on your url. Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted June 16, 2008 Author Share Posted June 16, 2008 I think my server is not sending headers properly? Link to comment Share on other sites More sharing options...
weaponx Posted June 16, 2008 Share Posted June 16, 2008 (edited) I think my server is not sending headers properly?I don't know. I can't test without a link. You could try capturing the headers in Firefox using the LiveHTTP Headers extension. Edited June 16, 2008 by weaponx Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted June 16, 2008 Author Share Posted June 16, 2008 Found my problem. I used a sniffer to track requests. Seems that my server does not send Content-Disposition filename. Link to comment Share on other sites More sharing options...
weaponx Posted June 16, 2008 Share Posted June 16, 2008 Found my problem.I used a sniffer to track requests.Seems that my server does not send Content-Disposition filename.Does the file have a default name when you click the link? If so then it has to be in the header somewhere. Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted June 16, 2008 Author Share Posted June 16, 2008 yes. it has. it is a .exe file. But seems that either php redirection does not work properly, or, the webserver does not send headers. it might be a mime-type issue. I will check and let you know. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now