Looking for a way to download specific files from a shared Google Drive. Something along the lines of a batch file would be great. Run it and it will download the 5/6 files needed and put them into a network drive location. Using Native windows stuff, no specific files (work related so restrictions on downloadss etc.).
I've tried a few things, but can't seem to get my head around it.
Things I have tried so far:
Tried using PowerShell, in various forms to do this. But have a funny feeling that the corporate proxy is blocking it from working.
Have tried:
$client = new-object System.Net.WebClient
$client.Credentials = Get-Credential
$client.Proxy.Credentials[System.Net.CredentialCache]::DefaultNetworkCredentials
$client.DownloadFile("https://docs.google.com/a/mydomain.co.uk/spreadsheets/d/1in0m8PhfiYhu4qCWO1dxNc3OS3p8prF7HWRZ-bjnKBI/export?format=xlsx","W:\Corp\Comp Serv\Comp Op\Op Br\Dep Data\Call\Rota\WTR.xlsx")
And:
$source = "https://docs.google.com/a/mydomain.co.uk/spreadsheets/d/1in0m8PhfiYhu4qCWO1dxNc3OS3p8prF7HWRZ-bjnKBI/export?format=xlsx"
$dest = "W:\Corp\Comp Serv\Comp Op\Op Br\Dep Data\Call\Rota\WTR.xlsx"
$WebmyClient = New-Object System.Net.WebClient
$WebProxy = New-Object System.Net.WebProxy("http://myproxy.com:1111",$true)
$Credentials = New-Object Net.NetworkCredential("user,"","domain.local")
$Credentials = $Credentials.GetCredential("http://myproxy.com","1111", "KERBEROS");
$WebProxy.Credentials = $Credentials
$WebClient.Proxy = $WebProxy
$WebClient.DownloadFile($source,$dest)
Tried doing this using bitsadmin, but have had no luck, it returned - 'Unable to add file - 0x80070005'
bitsadmin /transfer myDownloadJob /download /priority normal https://docs.google.com/a/mydomain.co.uk/spreadsheets/d/1in0m8PhfiYhu4qCWO1dxNc3OS3p8prF7HWRZ-bjnKBI/export?format=xlsx W:\Corp\Comp Serv\Comp Op\Op Br\Dep Data\Call\Rota\WTR.xlsx
Tried doing it via batch but no joy. Using this script I found online:
@echo off
setlocal
:: uses bitsadmin utility to download a file
:: bitsadmin is not available in winXP Home edition
:: the only way to download a file with 'pure' batch
:download
if "%2" equ "" (
call :help
exit /b 5
)
if "%1" equ "" (
call :help
exit /b 6
)
set url=%~1
set file=%~2
rem ----
if "%~3" NEQ "" (
set /A timeout=%~3
) else (
set timeout=5
)
bitsadmin /cancel download >nul
bitsadmin /create /download download >nul
call bitsadmin /addfile download "%url%" "%CD%\%file%" >nul
bitsadmin /resume download >nul
bitsadmin /setproxysettings download AUTODETECT >nul
set /a attempts=0
:repeat
set /a attempts +=1
if "%attempts%" EQU "10" (
echo TIMED OUT
endlocal
exit /b 1
)
bitsadmin /info download /verbose | find "STATE: ERROR" >nul 2>&1 && endlocal && bitsadmin /cancel download && echo SOME KIND OF ERROR && exit /b 2
bitsadmin /info download /verbose | find "STATE: SUSPENDED" >nul 2>&1 && endlocal && bitsadmin /cancel download &&echo FILE WAS NOT ADDED && exit /b 3
bitsadmin /info download /verbose | find "STATE: TRANSIENT_ERROR" >nul 2>&1 && endlocal && bitsadmin /cancel download &&echo TRANSIENT ERROR && exit /b 4
bitsadmin /info download /verbose | find "STATE: TRANSFERRED" >nul 2>&1 && goto :finishing
w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:%timeout% >nul 2>&1
goto :repeat
:finishing
bitsadmin /complete download >nul
echo download finished
endlocal
goto :eof
:help
echo %~n0 url file [timeout]
echo.
echo https://docs.google.com/a/domainname.co.uk/spreadsheets/d/1in0m8PhfiYhu4qCWO1dxNc3OS3p8prF7HWRF-bjnKBI/export?format=xlsx
echo W:\Corp\Comp Serv\Comp Op\Op Br\Dep Data\Call\Rota\WTR.xlsx
echo 10
echo.
goto :eof