How we can open torrent files in C#


How we can open torrent files in C#

Is possible to open torrent file in C# Code like

https://www.seedr.cc/


Asked by:- RahulMungra
0
: 87 At:- 12/16/2020 1:36:29 PM
c# mvc .NET






1 Answers
profileImage Answered by:- vikas_jk

Yes, it is possible to download file using torrent in C#, here is .NET Core sample

public void Run()
{
    int listeningPort = 4000; // must be available and between 1025 and 65535
    string baseDirectory = @".\Test"; // base torrent data directory
    string torrentInfoFilePath = @".\TorrentFile.torrent";
    TorrentClient torrentClient;

    if (TorrentInfo.TryLoad(torrentInfoFilePath, out TorrentInfo torrent))
    {
        torrentClient = new TorrentClient(listeningPort, baseDirectory);
        torrentClient.DownloadSpeedLimit = 100 * 1024; // 100 KB/s
        torrentClient.UploadSpeedLimit = 200 * 1024; // 200 KB/s
        torrentClient.TorrentHashing += this.TorrentClient_TorrentHashing;
        torrentClient.TorrentLeeching += this.TorrentClient_TorrentLeeching;
        torrentClient.TorrentSeeding += this.TorrentClient_TorrentSeeding;
        torrentClient.TorrentStarted += this.TorrentClient_TorrentStarted;
        torrentClient.TorrentStopped += this.TorrentClient_TorrentStopped;
        torrentClient.Start(); // start torrent client
        torrentClient.Start(torrent); // start torrent file
    }
}

private void TorrentClient_TorrentHashing(object sender, TorrentHashingEventArgs e)
{
    // occurs when a torrent's pieces are being hashed
    Console.WriteLine($"hashing {e.TorrentInfo.InfoHash}");
}

private void TorrentClient_TorrentLeeching(object sender, TorrentLeechingEventArgs e)
{
    // occurs when a torrent is being leeched (pieces are being downloaded)
    Console.WriteLine($"leeching {e.TorrentInfo.InfoHash}");
}

private void TorrentClient_TorrentSeeding(object sender, TorrentSeedingEventArgs e)
{
    // occurs when a torrent is being seeded (pieces are being uploaded)
    Console.WriteLine($"seeding {e.TorrentInfo.InfoHash}");
}

private void TorrentClient_TorrentStarted(object sender, TorrentStartedEventArgs e)
{
    // occurs when a torrent is started
    Console.WriteLine($"started {e.TorrentInfo.InfoHash}");
}

 private void TorrentClient_TorrentStopped(object sender, TorrentStoppedEventArgs e)
{
    // occurs when a torrent is stopped
    Console.WriteLine($"stopped {e.TorrentInfo.InfoHash}");
}

Source: https://github.com/aljazsim/torrent-client-for-net

OR you can also try these Nuget package

https://www.nuget.org/packages/Leak.Core/

https://www.nuget.org/packages/MonoTorrent/

I haven't used any of the above, but using these packages should work.

0
At:- 12/16/2020 2:36:10 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use

Subscribe Now

Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly