簡體   English   中英

使用monotorrent c#創建torrent

[英]Creation of torrent using monotorrent c#

我正在嘗試使用monotorrent為我桌面上的文件創建一個torrent,我嘗試過以下代碼

我能夠得到字節碼我無法將其保存為torrent顯示訪問被拒絕

enter code here  string path = "C:/Users/snovaspace12/Desktop/monotorrent-0.90/files";
        string savepath = "D:/results";

        TorrentCreator nnnn = new TorrentCreator();
        nnnn.CreateTorrent(path, savepath);

   public void CreateTorrent(string path, string savePath)
    {
        // The class used for creating the torrent
        TorrentCreator c = new TorrentCreator();

        // Add one tier which contains two trackers
        //RawTrackerTier tier = new RawTrackerTier();
        //tier.Add("http://localhost/announce");

        //c.Announces.Add(tier);
        c.Comment = "This is the comment";
        c.CreatedBy = "Doug using " + VersionInfo.ClientVersion;
        c.Publisher = "www.aaronsen.com";

        // Set the torrent as private so it will not use DHT or peer exchange
        // Generally you will not want to set this.
        c.Private = true;

        // Every time a piece has been hashed, this event will fire. It is an
        // asynchronous event, so you have to handle threading yourself.
        c.Hashed += delegate(object o, TorrentCreatorEventArgs e)
        {
            Console.WriteLine("Current File is {0}% hashed", e.FileCompletion);
            Console.WriteLine("Overall {0}% hashed", e.OverallCompletion);
            Console.WriteLine("Total data to hash: {0}", e.OverallSize);
        };

        // ITorrentFileSource can be implemented to provide the TorrentCreator
        // with a list of files which will be added to the torrent metadata.
        // The default implementation takes a path to a single file or a path
        // to a directory. If the path is a directory, all files will be
        // recursively added


        ITorrentFileSource fileSource = new TorrentFileSource(path);

        // Create the torrent file and save it directly to the specified path
        // Different overloads of 'Create' can be used to save the data to a Stream
        // or just return it as a BEncodedDictionary (its native format) so it can be
        // processed in memory
        c.Create(fileSource, savePath);
    }
    public void Create(ITorrentFileSource fileSource, string savePath)
    {

        Check.SavePath(savePath);


        var file = Create(fileSource);//getting the fbyte code 
        File.WriteAllBytes( savePath, Create(fileSource).Encode()); //getting exception here 

    }

當我檢查字節代碼正確返回到文件

它顯示訪問被拒絕

你可能已經解決了這個問題,但我遇到了同樣的問題。 至少在我的情況下,解決方案非常簡單。

問題源於c.Create(fileSource, savePath )中的savePath參數;

我假設savePath是一個保存torrent的目錄。 它應該是一個文件路徑。 例如savePath =“C:\\ pathtomytorrents \\ content.torrent”

希望這對你有用!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM