Sign in to follow this  
Followers 0
LapidusCreatorium

InetGet file name

12 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

$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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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())

Share this post


Link to post
Share on other sites

Yes, it is working for URL http://www.shsforums.net/index.php?automod...load&id=141

But 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.

Share this post


Link to post
Share on other sites

I think my server is not sending headers properly?

Share this post


Link to post
Share on other sites

#9 ·  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

Share this post


Link to post
Share on other sites

Found my problem.

I used a sniffer to track requests.

Seems that my server does not send Content-Disposition filename.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0