我将从Windows 7中的.bat脚本下载一个文件,并将其放入当前文件夹(脚本所在的位置)。
我以这种方式尝试,没有(好的)结果:
SET FILENAME = "name.ext" bitsadmin.exe /transfer "JobName" http://www.someurl.com/file.ext %cd%%FILENAME%
我懂了:
Unable to add file - 0x80070005
为什么? 我想这个string连接失败
在已经运行的batch file上设置进程优先级
批量手动运行良好。 但是从任务计划程序运行时出现错误
如何有效地从registry读取GUID?
Windows蝙蝠:目录中的循环文件
(我知道bitsadmin在Win7中已弃用)
先谢谢你!
使用正确的JRE从batch file中提取Java应用程序
如何将一个variables设置为Windows上父目录的path?
通过批处理脚本更新多个heroku应用程序
你的问题是等号两边的空格。 它们被包含在变量名称和变量的内容中 – 加上缺少反斜杠。
测试这个:
@echo off SET "FILENAME=%~dp0name.ext" bitsadmin.exe /transfer "JobName" http://www.someurl.com/file.ext "%FILENAME%"
因为使用提升的权限运行时,工作目录会改变。
当你说某事不起作用时,请报告所有的错误消息,所以问题可以解决。
我自己解决,而不使用FILENAME变量:
bitsadmin.exe /transfer "JobName" http://www.someurl.com/file.ext "%cd%name.ext"
电源外壳
start-bitstransfer -source protocol://url.host/url.path -destination C:destinationfile.ext
从cmd env
powershell -command "start-bitstransfer -source protocol://url.host/url.path -destination C:destinationfile.ext"
参考
我认为Bitsadmin不能使用相对路径,并且需要将全名添加到本地文件中。
你也可以检查我的bitsadmin脚本花了很多肮脏的工作 – 它接受两个参数的url和本地文件的路径(和一个超时号码 – 默认是5)。你可以看到它预先%CD%到本地文件名称:
@echo off setlocal :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 url - the source for download echo file - file name in local directory where the file will be stored echo timeout - number in seconds between each check if download is complete (attempts are 10) echo. goto :eof
你也可以检查这个jscript.net自编译的混合(保存为.bat):
@if (@X)==(@Y) @end /****** jscript comment ****** @echo off :::::::::::::::::::::::::::::::::::: ::: compile the script :::: :::::::::::::::::::::::::::::::::::: setlocal if exist simpledownloader.exe goto :skip_compilation set "frm=%systemRoot%Microsoft.NETFramework" :: searching the latest installed .net framework for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%systemRoot%Microsoft.NETFrameworkv*"') do ( if exist "%%vjsc.exe" ( rem :: the javascript.net compiler set "jsc=%%~dpsnfxvjsc.exe" goto :break_loop ) ) echo jsc.exe not found && exit /b 0 :break_loop call %jsc% /nologo /out:"simpledownloader.exe" "%~dpsfnx0" :::::::::::::::::::::::::::::::::::: ::: end of compilation :::: :::::::::::::::::::::::::::::::::::: :skip_compilation :: download the file :: :::::::::: simpledownloader.exe "%~1" "%~2" :::::::: :: exit /b 0 ****** end of jscript comment ******/ import System; var arguments:String[] = Environment.GetCommandLineArgs(); var webClient:System.Net.WebClient = new System.Net.WebClient(); print("Downloading " + arguments[1] + " to " + arguments[2]); try { webClient.DownloadFile(arguments[1],arguments[2]); } catch (e) { Console.BackgroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("nnProblem with downloading " + arguments[1] + " to " + arguments[2] + "Check if the internet address is valid"); Console.ResetColor(); Environment.Exit(5); }
@echo off SET "FILENAME=%~dp0name.ext" bitsadmin.exe /transfer "JobName" http://www.someurl.com/file.ext "%FILENAME%" pause
这个工作。 只要改变一下
SET "FILENAME=%~dp0name.ext"
至
SET "FILENAME=%~dp0Your File Name"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。