2

I'm trying to create a script that has multiple wget commands that include site credentials to download a file. If I run the wget command individually in a command prompt, the file downloads properly.

If I create a batch script to include multiple wget commands, none of the files download properly. I'm not proficient in scripting and haven't found a solution online. Is it possible to run multiple wget commands within a batch file?

This is an example of my batch script.

 q@echo off
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%yyyy%%mm%%dd%


wget -v --http-user="username" --http-password=password "http://server/dira/file:format=PDF" -O "C:\test\%date%file.pdf"

wget -v --http-user="username" --http-password=password "http://server/dirb/file2:format=PDF" -O "C:\test\%date%file.pdf"
  • what does "none of the files download properly" mean? any errors? – Dusan Bajic Jul 26 '12 at 10:26
  • They download "corrupted" with 0k in size. – Rowell Jul 26 '12 at 13:08
2

If you know the URLs you are wanting to download from you could store the download files or URLs in a text file then use the wget -i option

This question here posted on SuperUser may help out as well

  • The challenge I came across with this option is that I need to rename the file being downloaded to have today's date appended to it. Each file had a different name and didn't follow any numerical structure such as file1, file2, file3, etc. – Rowell Jul 25 '12 at 21:07
  • So are you trying to download multiple PDF files from a specific site then? Cause if so you can set to download all files of that type from a website with wget as well. I noticed you said they downloads were corrupt, have you tried your script out elsewhere? – JMeterX Jul 26 '12 at 13:36
0

I'd use PowerShell.

#Feel free to modify date format via google search
$dateString = Get-Date -f MM-dd-yy
$client = New-Object System.Net.Webclient
$client.Credentials = New-Object System.Net.NetworkCredential("user","pass")


"File1.pdf","File2.pdf","file3.zip" | % {
    $path = "http://somesite.com/files/" + $_
    $fileName =  "C:\downloads\" + ($_).Replace(".zip",($dateString + ".zip"))
    $client.DownloadFile($path,$fileName)
}
0

If one wants to download multiple files using wget the best way is to add "start" to at beginning of every line. Like:

start wget -v --http-user="username" --http-password=password "http://server/dira/file:format=PDF" -O "C:\test\%date%file.pdf

If one wants to avoid each line opening a new cmd window use /B option. Like:

start /B wget -v --http-user="username" --http-password=password "http://server/dira/file:format=PDF" -O "C:\test\%date%file.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.