Jump to content

General Downloader


Nutster
 Share

Recommended Posts

On some systems I work on, the web browser has been adjusted to prevent downloads, particularly publicly used computers, like in the library. So If I want to actually download something onto my USB flash stick, I just use the following script, compiled on the stick. It asks a couple of questions and then downloads into the Download directory on the same drive as the compiled script. It also includes a decent version of BaseName.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=H:\AutoIt\General Download.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Au3Check_Stop_OnWarning=y
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/sci 1 /sf
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/striponly /sci 1
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.10.0
    Author:         "Nutster" David Nuttall
    
    Script Function:
    Download a file that is given in the InputBox
    
#ce ----------------------------------------------------------------------------

AutoItSetOption("MustDeclareVars", True)

Global $sURL, $sFileName
Global $sDrive = StringLeft(@ScriptDir, 2) ; should contain <drive>:, like H:
Global $sPrefix = $sDrive & "\Download\"

$sURL = InputBox(@ScriptName, "Enter the URL to download.", "", " M")
If StringStripWS($sURL, 3) = "" Then Exit
$sFileName = InputBox(@ScriptName, "Enter the local filename.", BaseName($sURL), " M")
If StringStripWS($sFileName, 3) = "" Then Exit

InetGet($sURL, $sPrefix & $sFileName, 1, 0)

MsgBox(64, "File Download", "Task Complete")

Func BaseName($sFileName)
    Local $I = StringInStr($sFileName, "/", 0, -1)
    
    If $I = 0 Then $I = StringInStr($sFileName, "\\", 0, -1)
    If $I = 0 Then
        Return $sFileName
    Else
        Return StringMid($sFileName, $I + 1)
    EndIf
EndFunc   ;==>BaseName

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

I rewrote your script as a function to fit my needs. Hopefully someone else can use it as well.

Func httpsave($sURL, $sFileName = '', $sDirectory = @ScriptDir)
    If $sFileName = '' Then $sFileName = BaseName($sURL)
    Select
        Case StringStripWS($sFileName, 8) = ""
        Case StringStripWS($sURL, 3) = ""
        Case Else
            InetGet($sURL, $sDirectory & '\' & $sFileName, 1, 0)
    EndSelect
EndFunc  ;==>httpsave
Edited by daslick
Link to comment
Share on other sites

I rewrote your script as a function to fit my needs. Hopefully someone else can use it as well.

Func httpsave($sURL, $sFileName = '', $sDirectory = @ScriptDir)
    If $sFileName = '' Then $sFileName = BaseName($sURL)
    Select
        Case StringStripWS($sFileName, 8) = ""
        Case StringStripWS($sURL, 3) = ""
        Case Else
            InetGet($sURL, $sDirectory & '\' & $sFileName, 1, 0)
    EndSelect
EndFunc ;==>httpsave
why have you added two pointless Case statements? 4_4
Link to comment
Share on other sites

Func httpsave($sURL, $sFileName = '', $sDirectory = @ScriptDir)
    If $sFileName = '' Then $sFileName = BaseName($sURL)
    Select
        Case StringStripWS($sFileName, 8) = ""
        Case StringStripWS($sURL, 3) = ""
        Case Else
            InetGet($sURL, $sDirectory & '\' & $sFileName, 1, 0)
    EndSelect
EndFunc;==>httpsave

I used the two 'pointless' Case statements to catch the cases where sFileName or sURL were empty (or all spaces) and abort trying to InetGet

Link to comment
Share on other sites

  • Moderators

If you really want to get down and dirty with it:

_URLSplit

Edit:

Added UDF name

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

My batch downloader

#include <File.au3>
Dim $szDrive, $szDir, $szFName, $szExt
$line = _FileCountLines ( @scriptdir & "\list.ini" )
for $i = 1 to $line
$path = FileReadLine ("list.ini",$i)
if $path = "OK" then ContinueLoop
$size =InetGetSize ( $path )
$name = _PathSplit ($path, $szDrive, $szDir, $szFName, $szExt)
InetGet($path, $name[3]&$name[4], 1, 1)
ProgressOn ("Batch Download",$name[3]&$name[4])
While @InetGetActive
  ProgressSet ((@InetGetBytesRead/$size)*100, Int((@InetGetBytesRead/$size)*100)& " %" & "      Bytes: " & $size )
  sleep (500)
Wend
if FileExists($name[3]&$name[4]) then  _FileWriteToLine (@scriptdir & "\list.ini",$i,"OK",1)
next
Edited by HAL9000
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...