Announcement

Collapse
No announcement yet.

Batch: CMD HTTP download

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch: CMD HTTP download

    Well,
    Because i've some time I'm trying to make a batch script with a For loop.


    Code:
    for %i in ("type play.txt | find /v "play"") do wget %i
    So whats in play.txt
    well some strings like:

    # date play with some scripting....
    www.downloadsite.com/something.txt
    Marcel
    Technical Consultant
    Netherlands
    http://www.phetios.com
    http://blog.nessus.nl

    MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
    "No matter how secure, there is always the human factor."

    "Enjoy life today, tomorrow may never come."
    "If you're going through hell, keep going. ~Winston Churchill"


  • #2
    Re: Batch: CMD HTTP download

    found it....

    Code:
    for /F %i IN ('type play.txt ^| find /v "play"') do wget %i
    Marcel
    Technical Consultant
    Netherlands
    http://www.phetios.com
    http://blog.nessus.nl

    MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
    "No matter how secure, there is always the human factor."

    "Enjoy life today, tomorrow may never come."
    "If you're going through hell, keep going. ~Winston Churchill"

    Comment


    • #3
      Re: Batch: CMD HTTP download

      Originally posted by Dumber View Post
      found it....

      Code:
      for /F %i IN ('type play.txt ^| find /v "play"') do wget %i
      great!

      And is the downloading working too with wget.exe?

      remark;
      Use a single %-sign for the loop-variable only if you run your sample as a command-line. You must use double %%-sign when writing it in a batch!

      ps
      For your batch you might want to increase the Number of Simultaneous HTTP Sessions
      http://www.pctools.com/guides/registry/detail/536/




      More about FOR /F

      A single '%'-sign for %i is if you run the command from a command prompt. If you want to use the command in a batch file use them double '%%i'

      In a For loop you cannot use quotes within doublequotes, there for use a single-quote sign for the entire *command* and Double-quote signs around paths thare are used for the command. And you must 'escape'the pipe sign "|" like this ^| if it is within the single quotes.
      (Do not use single quote signs if it is not a command-line, for instance you want to read a specified textfile w/out using the Type command).

      The For command w/out a switch can only go through a list of elements, separated by either spaces, comma's or semicolons.
      In a NT shell you can use the switch For /F, that makes it possible to read returns of commands, or read content.

      The i in %i from you batch may be replaced by any character, either upper case or lower case, except numbers. But Note that variables are case sensitive so be consistent. (In my examples below, I didn't use a letter for this special variable, just because I did not use delims and there was only just one option for tokens, that is why I could also use "*" here as the variable instead of a letter)


      Code:
      @echo Off
      FOR /F "tokens=* delims=" %%* in ('type "c:\myfile.txt" ^|FindStr /i /v /b ";"') do @echo %%*
      pause
      Or, start all the lines in the txtfile you want to skip with a semicolon (like in 'ini files') and use this command

      Code:
      @echo Off
      FOR /F "usebackq eol=; tokens=* delims=" %%* in ("c:\myfile.txt") do @echo %%*
      pause
      Instead off typing ... In ('type "c:\my text file.txt"') Do ..., you can use usebackq (to use quotation marks) and just type: ... In ("c:\my text file.txt") Do ...

      \Rems


      just an example ( using && and || as result-handlers):
      Code:
      @@@Title,Internet Playlist -running-
      @@@Color 9E
      @echo off
      
      :: download files
      Set "$FileType=.mp3"
      
      :: read URLs from file
      Set "$PlayList=c:\play.txt"
      
      :: skip lines starting with "#"
      For /f "usebackq eol=#" %%i IN ("%$PlayList%") Do (
      :: filter file types...
        echo."%%i"|FindStr /i "%$FileType%\>">nul && (
          echo.%%i  - "filetype is %$FileType%")  || (
          echo.%%i  - "is not a %$FileType%")
      :: progress indicator...
       echo.done ^<%%i^>,&echo.)
      
      @@@Title,Internet Playlist -ended-
      @@@Color 30
      echo.&echo.finished!
      pause>nul
      Last edited by Rems; 24th January 2008, 18:17. Reason: (forgot...) added "usebackq" to the last batch

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: Batch: CMD HTTP download

        Thanks Rems. I will have a look at it.
        Yes the download works with Wget. It's a nice small utility

        It's a long time that i've used scripting...
        Last edited by Dumber; 10th January 2008, 16:12.
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment

        Working...
        X