Jump to content
kevinlaikf

How to Download file from the web via AutoIT?

Recommended Posts

kevinlaikf

I wish to retrieve a file from a webserver (HTTP) periodically from an web-connected PC.

I need more information on the use of InetGet.

Any example scripts?

Edited by kevinlaikf

Share this post


Link to post
Share on other sites
dbzfanatic

Copied from helpfile

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)

Share this post


Link to post
Share on other sites
Diana (Cda)

Just wanted to share what I did with the information. I've set a reminder program to launch this script in the early morning so that before work, I have a local, small free newspaper dl to my news folder:

;
; AutoIt 3x
;
#include <_PartitionLetters.au3>     ; this replaces drive letters
#include<_WEReplacement.au3>     ; references a Windows Explorer replacement program
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon(@ScriptDir & "\Download Metro newspaper daily.ico")     ; changes the icon displayed in the systray

;-----------------------------------------------------------------------------------------------------------------------
#Include <Date.au3>
; Short day of the week, i.e., Monday = Mon
$ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(@WDAY,1) ), 2)
$2digitYEAR = StringRight(@YEAR, 2)
;-----------------------------------------------------------------------------------------------------------------------
$YrDate_Short      = $2digitYEAR & @MON & @MDAY & "." & $ShortDayMyFormat
$YrDate_Long       = @YEAR & "." & @MON & "." & @MDAY & "." & $ShortDayMyFormat
$PunctuationBridge = "., "
$Time              = @HOUR & "h" & @MIN & "m" & @SEC & "s"
;-----------------------------------------------------------------------------------------------------------------------

;==========================================================================================================================
$URL2dlFrom = "http://edition.pagesuite-professional.co.uk/create_whole_pdf.aspx?PBID=d91faed2-f1cf-43ac-b12c-2a67eb85d750"
$SavePDF2   = @ScriptDir & "\Metro news- "
$SavePDF2  &= $YrDate_Short & $PunctuationBridge & $Time & ".pdf"
;==========================================================================================================================

Beep(4500, 10)
Beep(5500, 15)
Beep(4500, 10)
Beep(5500, 15)
Beep(4500, 10)
Beep(5500, 15)
Sleep(2500)
TrayTip("", "Downloading today's Metro newspaper edition ...", 45)
InetGet($URL2dlFrom, $SavePDF2, 1)




#cs
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)
#ce


#cs
HELP PAGE:
--------------------------------------------------------------------------------
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. Can be "abort". 
    filename [optional]
    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.

To abort a download call the function with just the first parameter set to "abort" like so:
    InetGet("abort")
#ce

If the URL stays consistently the same, this should work daily.

Thanks. <g>

Share this post


Link to post
Share on other sites
ur
Posted (edited)
On 8/22/2008 at 1:58 PM, dbzfanatic said:

Copied from helpfile

 

 

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)

Hi @dbzfanatic, I am getting error as macro not found for @InetGetBytesRead .

I have already included #include <InetConstants.au3>

Could you please suggest.

Edited by ur

Share this post


Link to post
Share on other sites
Jos

@ur, 

Did you notice that this thread is "somewhat old"?
Did you open the helpfile to search for @InetGetBytesRead as any variable starting with @ is an internal macro?

Your move.
Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
ur
Posted (edited)

Sorry, It seems all the macros defined here are replaced with InetGetInfo function


 
Edited by ur

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

×