Windows 命令行实用程序从 http:// 和 file:// 下载并带有进度

Windows 命令行实用程序从 http:// 和 file:// 下载并带有进度

是否有一个 Windows 命令行实用程序支持从 和http://进行file://下载progress

已经尝试过:

  • powershell Invoke-WebRequest:在 Windows 7 上不起作用
  • powershell (New-Object Net.WebClient).DownloadFile():没有报告进展
  • bitsadmin:在 Windows 7 上速度很慢,显示“已弃用”,并且不会将进度输出到标准输出

用法:

powershell -Command "(New-Object Net.WebClient).DownloadFile('http://server/test.txt', 'D:\test.txt')"
powershell -Command "(New-Object Net.WebClient).DownloadFile('file://server/test.txt', 'D:\test.txt')"
powershell -Command "(New-Object Net.WebClient).DownloadFile('file:///C:/test.txt', 'D:\test.txt')"

powershell -Command "Invoke-WebRequest 'http://server/test.txt' -UseBasicParsing -OutFile 'D:\test.txt'"
powershell -Command "Invoke-WebRequest 'file://server/test.txt' -UseBasicParsing -OutFile 'D:\test.txt'"
powershell -Command "Invoke-WebRequest 'file:///C:/test.txt' -UseBasicParsing -OutFile 'D:\test.txt'"

bitsadmin /transfer Job1 /download /priority normal "http://server/test.txt" "D:\test.txt"
bitsadmin /transfer Job1 /download /priority normal "file://server/test.txt" "D:\test.txt"
bitsadmin /transfer Job1 /download /priority normal "file:///C:/test.txt" "D:\test.txt"

答案1

如果您对两个应用程序都没问题,copy /z则会为您提供本地文件的完成百分比:

在此处输入图片描述

对于 http(s) wget适用于 Windows

在此处输入图片描述

答案2

我最终制作了这个小型的.net 控制台应用程序

static int Main(string[] args)
{
    if (args.Length < 2)
    {
        Console.Error.WriteLine("invalid arguments!");
        return -1;
    }

    try
    {
        var source = args[0];
        var destination = args[1];

        var webClient = new WebClient();

        webClient.DownloadProgressChanged += (s, e) => Console.WriteLine("{0} of {1} bytes, {2}% downloaded...", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage);
        webClient.DownloadFileCompleted += (s, e) => Console.WriteLine("Download completed: {0} to {1}", source, destination);

        Console.WriteLine("Download started: {0} to {1}", source, destination);
        webClient.DownloadFileTaskAsync(new Uri(source), destination).Wait();
        return 0;
    }
    catch(Exception x)
    {
        Console.Error.WriteLine(x.Message);
        return -2;
    }
}

相关内容