【发布时间】:2013-10-22 11:29:11
【问题描述】:
我是 PowerShell 的新手,我正在尝试创建一个简短的脚本,可以在页面上找到磁性链接并下载它们。
我不太了解磁性 URI 的工作原理,而且我似乎无法让我的脚本通过它们下载文件。
我正在使用以下代码sn-p:
$webclient = New-Object System.Net.WebClient
$url = "magnet:?xt=urn:btih:44bb5e0325b7dad0bdc5abce459b85b014766ec0&dn=MY_TORRENT&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp"
$file = "C:\Some\Path\myfile.torrent"
$webclient.DownloadFile($url, $file)
这会产生以下异常
System.Management.Automation.MethodInvocationException: Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request." ---> System.Net.We
bException: An exception occurred during a WebClient request. ---> System.NotSupportedException: The URI prefix is not recognized.
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
at System.Net.WebClient.GetWebRequest(Uri address)
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
--- End of inner exception stack trace ---
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at CallSite.Target(Closure , CallSite , Object , Object , Object )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo member
Info)
at CallSite.Target(Closure , CallSite , Object , Object , Object )
at System.Management.Automation.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
在 PowerShell 中是否有不同的下载方式,或者这不能通过磁链接实现。
我的最终目标是通过磁力链接开始下载 torrent,所以也许可以通过链接打开一个 torrent 客户端,但我不知道该怎么做。
【问题讨论】:
标签: powershell download powershell-3.0 utorrent magnet-uri