gpt4 book ai didi

powershell - 使用Powershell 3下载磁链接

转载 作者:行者123 更新时间:2023-12-03 00:38:57 24 4
gpt4 key购买 nike

我是PowerShell的新手,正在尝试创建一个简短的脚本,该脚本将在页面上找到磁性链接并下载它们。

我对磁性URI的工作方式了解甚少,而且似乎无法让我的脚本通过它们下载文件。

我正在使用以下代码片段:

$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客户端,但是我不确定该怎么做。

最佳答案

如果您安装了torrent客户端(如µTorrent)并且将其设置为处理磁力链接,则只需从Powershell打开链接即可:

start "magnet:?xt=urn:btih:44bb5e0325b7dad0bdc5abce459b85b014766ec0&dn=MY_TORRENT&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp"

那应该打开torrent客户端。

您还可以使用命令行torrent客户端 aria2并下载:
aria2c "magnet:?xt=urn:btih:44bb5e0325b7dad0bdc5abce459b85b014766ec0&dn=MY_TORRENT&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp"

关于powershell - 使用Powershell 3下载磁链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19368028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com