2013-10-14 43 views
1

我是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客戶端,但我不確定我會怎麼做。

回答

2

如果你有一個像µTorrent洪流客戶端安裝並設置爲處理磁體鏈接,你可以打開從PowerShell中的鏈接:

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

這應該打開Torrent客戶端。

您還可以使用命令行洪流客戶aria2和下載:

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

+1 aria2c推薦 – Alex

3

Magnetic links使用協議magnet不是Windows本機支持,並且不支持DownloadFile()

如果您安裝了支持magnet協議的客戶端,它將爲magnet URI方案安裝protocol handler

這應該允許您使用Start-Process,僅傳遞磁性URL作爲參數,以調用該客戶端並使其通過該URL進行任何通常的處理。