Jump to content
Sign in to follow this  
sekyao

Alternative to URLDownloadTo

Recommended Posts

sekyao

Dear all,

i am currently creating an program to ping a certain URL and (if successful), send a GET id to the ping-ed url . part of the coding is as follow :

...

$str_url = "URL?B=" & $str_code 

If RunWait("ping.exe -n 1 " & "URL", "", @SW_HIDE) == 0 Then

                    ; Connection is established.

                    $str_result = URLDownloadToFile($str_url, $tmpFile)     

....

However, i have tested on several pc at different location and pc's setting. The problem i'm facing at the moment is that at some pc, the script work fine, while other would face problem, and thirdly ( at most confusing) it is pingable but the URLDownloadToFile does not transfer the $str_code to the URL.

So i was wandering if there is any alternative to URLDownloadToFile or advice on this matter?

Share this post


Link to post
Share on other sites
themax90

It must be an COMPLETE URL. Like http://www.autoitscript.com/index.html. URLDownlodToFile will not download Php documents or interlaced MySql stuff.

There is an alternative but it's in the Version 3.0.103 Beta which is unstable.

You can download the beta at http://www.autoitscript.com/autoit3/files/unstable/autoit/

or for the excutable

http://www.autoitscript.com/autoit3/files/...it-v3.0.103.exe

I'm not sure if Absolute Url's work, but you can always find out.

InetGet

--------------------------------------------------------------------------------

Downloads a file from the internet using the http or ftp protocol.

InetGet ( "URL", "filename" [, reload [, background]] )

Parameters

URL URL of the file to download. See remarks below.

filename Local filename to download to.

reload [optional]

0 = (default) Get the file from local cache if available

1 = Forces a reload from the remote site

background [optional]

0 = (default) Wait until the download is complete before continuing.

1 = return immediately and download in the background (see remarks).

Return Value

Success: Returns 1.

Failure: Returns 0.

Remarks

Internet Explorer 3 or greater must be installed for this function to work.

The URL parameter should be in the form "http://www.somesite.com/path/file.html" - just like an address you would type into your web browser.

To use a username and password when connecting simply prefix the servername with "username:password@", e.g.

"http://myuser:mypassword@www.somesite.com"

The InetGet function works with http:// https:// and ftp:// - to change the transfer type when using ftp see the FtpBinaryMode option.

"background" Parameter

By default the function waits until the download has finished before returning. Sometimes with large downloads this is not always wanted. If the background parameter is set to 1 the function returns immediately and the download continues in the background. When in this mode two macros are used to keep track:

@InetGetActive = 1 while downloading, or 0 when finished.

@InetGetBytesRead = the number of bytes downloaded, or -1 if there has been an error.

Note, only one download can be active at once, if you call the function again before a download is complete it will fail.

Related

FtpBinaryMode (Option), FtpSetProxy, InetGetSize, HttpSetProxy,

Example

InetGet("http://www.mozilla.org", "C:\foo.html")

InetGet("http://www.autoitscript.com", "C:\mydownload.htm", 1)

InetGet("ftp://ftp.mozilla.org/pub/mozilla.org/README", "README.txt", 1)

; Advanced example - downloading in the background

InetGet("http://www.nowhere.com/somelargefile.exe", "test.exe", 1, 1)

While @InetGetActive

  TrayTip("Downloading", "Bytes = " & @InetGetBytesRead, 10, 16)

  Sleep(250)

Wend

MsgBox(0, "Bytes read", @InetGetBytesRead)

Edited by Agent Smith

Share this post


Link to post
Share on other sites
sekyao

Thank you for the information. but i'm dont actually wanna download the file down. just wanna use autoIT to push a variable ( $str_code ) to URL if the ping result return sucess

Share this post


Link to post
Share on other sites
themax90

Then it must be a domain to Ping it, you cannot ping a file. Make sure it's a domain like www.google.com or www.mozilla.org.

It can also be an Ip address. You can to a domain query to find the main servers ip address of the domain and ping that.

Edited by Agent Smith

Share this post


Link to post
Share on other sites
sekyao

the domain to ping is correct. Have tried of manual ping as well as autoit ping and result obtained from ping == 0. also, i have written the ping statement as a if-else , so on else case, a log file would be created but so far no log file. so i doubt that the ping has failed.

Share this post


Link to post
Share on other sites
themax90

$str_url = "URL?B=" & $str_code 

$str_url = "URL?B=" & $str_code

Whats that stuff?

And you can't have a function in the If bar. Can you send me the source, I will debug it for you...

If RunWait("ping.exe -n 1 " & "URL", "", @SW_HIDE) == 0 Then

; Connection is established.

$str_result = URLDownloadToFile($str_url, $tmpFile)

Should be

$run = RunWait("ping.exe -n 1 " & "URL", "", @SW_HIDE)

If $run == 0 Then

; Connection is established.

$str_result = URLDownloadToFile($str_url, $tmpFile)

See you can't run a function if it is in the if statement. But it runs it right before the If statement and logs it in a variable. So it actually has something to do... Hehe

Edited by Agent Smith

Share this post


Link to post
Share on other sites
sekyao

b is a capture variable that is detected by URL to received the $str_code.

also, are you sure about RUNWAIT in a IF-ELSE statement?. some pc work fine with this setting. but,nontheless, i'll modify my coding and see if the problem is resolved or not.

Share this post


Link to post
Share on other sites
themax90

You can't have that capture there. It must be a literal string.

http://www.nowhere.com/somefile.exe is a good example.

you can't have http://www.nowhere.com/somefile.exe?b= & str_code

It must be the actual file other wise it will not work. Please give me a copy of the source and I will debug it for you.

Edited by Agent Smith

Share this post


Link to post
Share on other sites
sekyao

$str_url = "URL?B=" & $str_branch

Do

            If RunWait("ping.exe -n 1 " & "URL", "", @SW_HIDE) == 0 Then

                $int_count = 0

                    ; Connection is established.

                    $str_result = URLDownloadToFile($str_url, $tmpFile)                     

            Else

                ;Internet is down

                $int_count = $int_count + 1

                $str_resultfile2=      _FileWriteLog($str_file,  "Connection Lost")

                If  Mod ($int_count, 5 ) == 0  Then   

                    MsgBox(0, "Internet Connection", "Internet connection is down", 30)

                EndIf

            EndIf

               

            Sleep(300000)

Until $i = 0

note : actual URL is replaced with the term URL

sorry. but i cannot be more even specific nor provide additional information on the coding then those provided above.

Share this post


Link to post
Share on other sites
themax90

I am working on a duplicate WORKING script, I don't think u actually understand autoit completely

You must supply me with the full script otherwise none of us will be able to figure this out, don't worry we wont steal you stuff..

Edited by Agent Smith

Share this post


Link to post
Share on other sites
sekyao

nevermind , have found the solution.

thanks to all for the help

:idiot:

Share this post


Link to post
Share on other sites
sugi

And you can't have a function in the If bar. [...]

If RunWait("ping.exe -n 1 " & "URL", "", @SW_HIDE) == 0 Then

[...]

The AutoIt part of this line is valid. You can have a function in an expression.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.