Jump to content

Recommended Posts

Posted

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.

Posted (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]
EndFunc

Here is the original version I posted:

#525259

Edited by weaponx
Posted

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

Posted

$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

Posted

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? :)

Posted

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())
Posted (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 by weaponx
Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...