2014-09-01 120 views
0

我需要一个批处理文件中使用的命令,该文件通过http将远程目录的内容复制到本地目录。在windows批处理文件中通过http复制目录

比如复制文件夹中的http://路径//文件夹复制到C:\文件夹

我需要做到这一点无需安装任何额外的工具。

提前致谢!

+0

PowerShell/.net(或至少vbscript/jscript)是否被视为附加工具? – npocmaka 2014-09-01 08:37:47

+0

Powershell可以使用。 – fanciulla 2014-09-01 08:38:38

+0

我们需要看看你的尝试。您如何计划获取目录索引,因为HTTP不提供这样的机制? – CodeCaster 2014-09-01 10:04:38

回答

1

http服务器没有标准的方式来列出可访问的目录。

例如我把http://unomoralez.com/content/files/catalog2/source/作为用http列出目录的常用方法之一。你的网站可能看起来不一样,但是没有办法让我知道...(它是一个临时的list2.txt文件 - 你可以注释它的删除来检查目录页面的格式并告诉我它是否不工作。如果它是IIS可以看像这样:http://live.sysinternals.com/tools/

脚本下载所有的内容到.\download_dir(不递归下载):

@if (@X)==(@Y) @end /****** jscript comment ****** 

@echo off 
:::::::::::::::::::::::::::::::::::: 
:::  compile the script :::: 
:::::::::::::::::::::::::::::::::::: 
setlocal 
if exist simpledownloader.exe goto :skip_compilation 

set "frm=%SystemRoot%\Microsoft.NET\Framework\" 
:: searching the latest installed .net framework 
for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
    if exist "%%v\jsc.exe" (
     rem :: the javascript.net compiler 
     set "jsc=%%~dpsnfxv\jsc.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 


::::::::::::::::::::::::::::::::::::::::: 
::::just change the link and the file:::: 
::::::::::::::::::::::::::::::::::::::::: 


::!!!!!!!!!!!!!!!!!!!!!!!!!::: 
simpledownloader.exe "http://unomoralez.com/content/files/catalog2/source/" "list2.txt" 

md download_dir >nul 2>&1 

for /f "skip=1 tokens=4 delims=>< " %%a in ('type list2.txt^| find /i "href" ') do (
    simpledownloader.exe "http://unomoralez.com/content/files/catalog2/source/%%a" .\download_dir\%%a 
) 

del /q /f list2.txt 


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("\n\nProblem with downloading " + arguments[1] + " to " + arguments[2] + "Check if the internet address is valid"); 
     Console.ResetColor(); 
     Environment.Exit(5); 
} 

当你有powershell你也有.net所以这个代码将不适合你的问题被执行。

这或多或少是我已经拥有的代码,但是如果您熟悉cURL并创建混合jscript/.bat文件,您也可以检查这个代码 - >https://code.google.com/p/curlie/

相关问题