我是PowerShell的新手,我正在嘗試創建一個簡短的腳本,可以在頁面上找到磁鏈接並下載它們。下載與Powershell 3的磁性鏈接
我對磁性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客戶端,但我不確定我會怎麼做。
+1 aria2c推薦 – Alex