How to Get a Torrent File from a Magnet Link or Infohash

A practical guide to converting magnet links and bare infohashes into .torrent files using aria2c, BitTorrent clients, and other methods. Learn how the metadata discovery process works and which approach is best for your needs.

Jose Celano - 15/06/2026
How to Get a Torrent File from a Magnet Link or Infohash

Introduction

If you've spent any time in the BitTorrent ecosystem, you've likely encountered magnet links. They're everywhere — on torrent index sites, in chat rooms, and shared between users. But sometimes you need the actual .torrent file instead: perhaps for archiving, sharing with someone who prefers the old format, seeding on a tracker, or inspecting the metadata manually.

The core challenge is the same whether you have a magnet link or just a bare infohash: you need to fetch the metadata from the BitTorrent network. The infohash (a 20-byte SHA-1 hash) uniquely identifies a torrent, but it doesn't contain the file list, piece hashes, or other metadata — that information lives with peers who have the full torrent. A magnet link is simply a convenient URI that packages the infohash along with optional display names and tracker URLs.

In this guide, we'll explore several methods to obtain a .torrent file from a magnet link or infohash, starting with the simplest conceptual building block and building up to the most practical everyday tools.

Who needs this? If you're a BitTorrent developer, you might need the .torrent file to inspect metadata during testing. Tracker operators often see only an infohash in their logs and want to know what content it corresponds to. Self-hosters may need the file to register a torrent on a private tracker. And sometimes you just want to archive the metadata separately from the data — a .torrent file is a few hundred kilobytes, while the actual content can be gigabytes.

What's in a .torrent file? The .torrent file contains metadata only — the file list, piece hashes, piece length, and tracker URLs. It does not contain the actual file content. You still need a BitTorrent client to download the real data using this metadata. Think of it as a recipe describing the dish, not the dish itself.

A magnet link is a URI scheme that identifies a torrent by its infohash rather than by a file. Here's what a typical magnet link looks like:

text
magnet:?xt=urn:btih:dafc8c076ca2f3ed376eeae7c76a0d6be2415c45&dn=ubuntu-26.04-desktop-amd64.iso&tr=https%3a%2f%2ftorrent.ubuntu.com%2fannounce&tr=https%3a%2f%2fipv6.torrent.ubuntu.com%2fannounce

Let's break down the components:

  • xt=urn:btih:<infohash> — The essential part. xt stands for "exact topic", and urn:btih means this is a BitTorrent infohash (version 1). The 40-character hex string is the SHA-1 hash of the torrent's info dictionary. Everything else is optional. Base32 encoding (32 characters) is also supported for compatibility.
  • dn=<name> — The display name (optional). A human-readable filename for convenience before metadata is fetched.
  • tr=<url> — Tracker URLs (optional, repeatable). One or more tracker announce URLs to help discover peers.

The key insight: a bare infohash is all you truly need. If you remove everything from the magnet link except xt=urn:btih:<infohash>, you can still reconstruct the full magnet link manually. This means any tool or method that works with magnet links also works with bare infohashes — you just need to wrap the infohash in a minimal magnet URI first.

From a Bare Infohash to a Magnet Link

Tools like aria2c don't accept a bare infohash directly — they need a magnet link. So if all you have is a 40-character hex string like dafc8c076ca2f3ed376eeae7c76a0d6be2415c45, the first step is to wrap it in a magnet URI. You can do this manually:

bash
MAGNET="magnet:?xt=urn:btih:dafc8c076ca2f3ed376eeae7c76a0d6be2415c45"

For better results, add one or more tracker URLs to help with peer discovery:

bash
MAGNET="magnet:?xt=urn:btih:dafc8c076ca2f3ed376eeae7c76a0d6be2415c45&tr=https%3a%2f%2ftorrent.ubuntu.com%2fannounce&tr=https%3a%2f%2fipv6.torrent.ubuntu.com%2fannounce"

Once you have the magnet link, you can use any of the methods that follow. From this point on, there's no difference between a magnet link you constructed from an infohash and one you found on a website.

Pro tip: If you don't know which trackers to use, a good fallback is the ngosang trackers list or newTrackon, both community-maintained collections of public BitTorrent trackers. Adding a few reliable trackers significantly increases your chances of finding peers.

Method 1: Using aria2c (Recommended)

aria2 is a lightweight, multi-protocol download utility that supports BitTorrent with metadata fetching. It's the most straightforward tool for this job because it's available on all platforms, requires no GUI, and can be scripted easily.

Installation

aria2 can be installed via your system's package manager:

bash
# Debian / Ubuntu
sudo apt install aria2

# macOS (Homebrew)
brew install aria2

# Windows (Chocolatey)
choco install aria2

The Basic Command

To fetch the .torrent file from a magnet link without downloading the actual data, use:

bash
aria2c -d /tmp --bt-save-metadata=true --bt-metadata-only=true --follow-torrent=false "magnet:?xt=urn:btih:dafc8c076ca2f3ed376eeae7c76a0d6be2415c45&dn=ubuntu-26.04-desktop-amd64.iso&tr=https%3a%2f%2ftorrent.ubuntu.com%2fannounce&tr=https%3a%2f%2fipv6.torrent.ubuntu.com%2fannounce"

Let's break down each flag:

  • -d <directory> — The directory where the .torrent file will be saved. Below we use /tmp, but you can change it to any folder.
  • --bt-save-metadata=true — Save the fetched metadata (the .torrent file) to disk instead of discarding it after download.
  • --bt-metadata-only=true — Only fetch the metadata, don't download the actual file content. This is the key flag that tells aria2 to stop after getting the .torrent.
  • --follow-torrent=false — Don't automatically start downloading the torrent after fetching the metadata. Without this, aria2 would proceed to download the actual files.

Expected Output

Here's the real output from a successful run:

console
06/15 16:56:02 [NOTICE] Downloading 1 item(s)
06/15 16:56:02 [NOTICE] IPv4 DHT: listening on UDP port 6966
06/15 16:56:02 [NOTICE] IPv4 BitTorrent: listening on TCP port 6951
06/15 16:56:02 [NOTICE] IPv6 BitTorrent: listening on TCP port 6951
[#3495d8 485KiB/485KiB(100%) CN:43 SD:2]
06/15 16:56:45 [NOTICE] Download complete: [MEMORY][METADATA]ubuntu-26.04-desktop-amd64.iso
06/15 16:56:45 [NOTICE] Saved metadata as /tmp/dafc8c076ca2f3ed376eeae7c76a0d6be2415c45.torrent.

After about 45 seconds, aria2 discovered 43 peers (CN:43) with 2 seeders (SD:2) and saved the metadata as a .torrent file. The file is 485 KiB and contains the full torrent metadata.

Network requirements: aria2c opens random UDP and TCP ports for DHT and peer connections (as shown in the log output). If you're behind a firewall, VPN, or corporate network that blocks outbound peer-to-peer traffic, the metadata fetch may fail or time out. In that case, try adding more trackers to the magnet link, or use an online service as a last resort.

Using aria2c with a Bare Infohash

As shown above, you can construct the magnet link inline:

bash
aria2c -d /tmp --bt-save-metadata=true --bt-metadata-only=true --follow-torrent=false "magnet:?xt=urn:btih:dafc8c076ca2f3ed376eeae7c76a0d6be2415c45&tr=https%3a%2f%2ftorrent.ubuntu.com%2fannounce&tr=https%3a%2f%2fipv6.torrent.ubuntu.com%2fannounce"
Why aria2c is our top recommendation: It's a single command, works identically on Linux, macOS, and Windows, requires no GUI, and can be easily integrated into scripts. It's the fastest and most reliable way to get a .torrent file from a magnet link.

Method 2: Using Torrust Hash2Torrent

Torrust Hash2Torrent is a web service developed by the Torrust team that converts infohashes directly into .torrent files without needing a full BitTorrent client installation. It wraps the rqbit Rust BitTorrent client and uses BEP 9 metadata exchange to fetch the torrent file from peers.

The service was previously available at hash2torrent.com, but the public demo is currently paused. You can still run it locally from source or Docker:

Running Locally with Cargo

Make sure Rust is installed, then clone and run:

bash
git clone https://github.com/torrust/torrust-hash2torrent.git
cd torrust-hash2torrent

# Create the required session directory
sudo mkdir -p /var/lib/torrust/hash2torrent/session
sudo mkdir -p /var/lib/torrust/hash2torrent/torrents
sudo chown -R $(id -u):$(id -u) /var/lib/torrust/hash2torrent

# Run the server
cargo run

When the server starts, you'll see log output confirming it's ready:

console
2026-06-15T15:57:42.793Z  INFO torrust_hash2torrent: creating BitTorrent client and starting the session ...
2026-06-15T15:57:42.794Z  INFO librqbit::session: Listening on 0.0.0.0:51000 for incoming peer connections
2026-06-15T15:57:42.797Z  INFO librqbit_dht::dht: DHT listening on 0.0.0.0:53173
2026-06-15T15:57:42.806Z  INFO torrust_hash2torrent: starting API on: http://0.0.0.0:3000 ...

The server listens on port 3000 for HTTP API requests, port 51000 for incoming BitTorrent peer connections, and initialises the DHT on port 53173 to discover peers in the swarm.

Running Locally with Docker

bash
git clone https://github.com/torrust/torrust-hash2torrent.git
cd torrust-hash2torrent

# Create directories for persistent storage
mkdir -p ./storage/hash2torrent/lib ./storage/hash2torrent/log ./storage/hash2torrent/etc
sudo mkdir -p /var/lib/torrust/hash2torrent/session
sudo mkdir -p /var/lib/torrust/hash2torrent/torrents
sudo chown -R $(id -u):$(id -u) /var/lib/torrust/hash2torrent

# Build and run
./contrib/dev-tools/containers/docker-build.sh
./contrib/dev-tools/containers/docker-run.sh

Once the server is running, you can download the torrent file with curl. Here's the real output:

console
$ curl -o ./ubuntu-26.04-desktop-amd64.iso.torrent http://127.0.0.1:3000/torrents/dafc8c076ca2f3ed376eeae7c76a0d6be2415c45
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  486k  100  486k    0      0   264k      0  0:00:01  0:00:01 --:--:--  264k

While the request is being processed, the server logs what it does internally:

console
2026-06-15T16:00:37.756Z  INFO torrust_hash2torrent::api::handler: req: dafc8c076ca2f3ed376eeae7c76a0d6be2415c45
2026-06-15T16:00:39.583Z  INFO torrust_hash2torrent::api::cache: adding torrent to cache in /var/lib/torrust/hash2torrent/torrents/dafc8c076ca2f3ed376eeae7c76a0d6be2415c45.torrent

The server first logs the incoming request with the infohash, fetches the metadata from the BitTorrent network via rqbit, and caches the resulting .torrent file to disk so subsequent requests for the same infohash are served instantly.

The HTTP response returns a .torrent file with the correct content-type (application/x-bittorrent) and includes the infohash in the custom header X-Torrust-Torrent-Infohash for easy verification.

Note on trackers: BEP 9 only transfers the info dictionary of the torrent — the part covered by the infohash. Tracker URLs from your original magnet link are not preserved in the saved .torrent file. If you check the output of aria2c -S after downloading via hash2torrent, you'll notice the Announce: section is empty. You can re-add trackers manually, or rely on DHT for peer discovery.
Read more: Check out our dedicated post Hash2Torrent — Retrieve Torrent Files Effortlessly! for a deep dive into the service architecture and implementation.

Method 3: Using a BitTorrent Client (GUI)

If you prefer a graphical interface, most BitTorrent clients can add a magnet link and then export the .torrent file after the metadata is fetched.

qBittorrent

  1. Open qBittorrent and click File → Add Torrent Link (or press Ctrl+Shift+M).
  2. Paste the magnet link and click OK.
  3. Wait for the metadata to download (you'll see "Downloading metadata..." in the status).
  4. Right-click the torrent and select Advanced → Export .torrent File.

Transmission

  1. Open Transmission and click File → Open Torrent Address (or press Ctrl+Shift+O).
  2. Paste the magnet link and click Open.
  3. Once the metadata is fetched, the torrent file is stored in Transmission's config directory:
    • Linux: ~/.config/transmission/torrents/
    • macOS: ~/Library/Application Support/Transmission/Torrents/
  4. You can copy the .torrent file from there.
Note: GUI clients download the metadata as part of their normal operation. The .torrent export is effectively a snapshot of the metadata they've already fetched. If the torrent has no active peers, they may stall at "downloading metadata" indefinitely.

Method 4: Online Services (Use with Caution)

Several websites offer magnet-to-torrent conversion as a service. You paste a magnet link, and they return a downloadable .torrent file. One such example is magnet2torrent.com, which provides a simple paste-and-download interface.

Privacy considerations: When you use an online service, you're revealing the infohash — and thus your interest in that specific torrent — to a third party. If the torrent contains sensitive or copyrighted content, this could have implications. For private trackers, the tracker's own website is usually the safest place to download the original .torrent file.

Online services can be convenient if you're in a hurry or have no local tools available, but we recommend using aria2c or a local client whenever possible.

Overview of All Methods and Tools

Beyond the methods detailed above, there are many other tools and libraries that can convert an infohash or magnet link into a .torrent file. Here is a comprehensive reference:

CLI Tools

ToolLanguageExample CommandNotes
aria2cC++aria2c --bt-metadata-only --bt-save-metadata "magnet:?..."✅ Detailed above. Cross-platform.
rqbitRustrqbit download "magnet:?..."Full client with HTTP API. Powers Hash2Torrent.
transmission-cliCtransmission-remote --add "magnet:?..."Requires daemon. Extract .torrent from config dir.
webtorrent-cliJSwebtorrent "magnet:?..."Node.js. Can stream to stdout.
deluge-consolePythondeluge-console add "magnet:?..."Daemon-based. Uses libtorrent internally.

Web Services

ServiceURLNotes
Torrust Hash2Torrenthash2torrent.com (paused)Torrust's own service. Self-hostable.
magnet2torrent.commagnet2torrent.comBrowser-based. Privacy concerns apply.
webtor-ioGitHubgRPC service. Self-hostable (Go).

Libraries (for Developers)

LibraryLanguageNotes
librqbitRustCore library used by Hash2Torrent. Full BEP 9.
libtorrentC++ / PythonDe facto standard. Python bindings available.
WebTorrentJavaScriptStreaming client for Node.js and browser.
ut_metadataJavaScriptBEP 9 plugin for bittorrent-protocol.
bittorrent-dhtJavaScriptDHT client to find peers for custom flows.

Protocol-Level (DIY)

ApproachBEPDescription
DHT Lookup + BEP 9BEP 5, BEP 9Find peers via DHT, then request metadata via extension protocol.
Local Peer DiscoveryBEP 14Discover peers on LAN and fetch metadata (no internet needed).

Verifying the Downloaded Torrent File

Once you have the .torrent file, you can quickly verify its contents using aria2c itself — no additional tools needed:

bash
aria2c -S ubuntu-26.04-desktop-amd64.iso.torrent

This will list all files inside the torrent along with their sizes. If the output matches your expectations (e.g. you see ubuntu-26.04-desktop-amd64.iso with the expected size), the metadata was fetched correctly and the torrent file is valid.

For a deeper inspection, you can pipe the raw bencoded data through bencode2json, another small Torrust utility that converts bencode to JSON — a perfect example of the Unix philosophy of small, single-responsibility tools working together:

bash
bencode2json < ubuntu-26.04-desktop-amd64.iso.torrent | jq .info

This outputs the full metadata in a readable JSON format, which is useful for scripting or automated processing.

Troubleshooting Common Issues

No Peers Found

The most common issue is that the torrent has no active peers in the swarm. This can happen with old or unpopular torrents. Solutions:

  • Add more trackers: Append additional &tr=<url> parameters to the magnet link.
  • Wait longer: Some swarms are slow to respond. aria2c will keep retrying for a while.
  • Check DHT: Ensure DHT is enabled in your client. aria2c enables it by default.

Metadata Download Times Out

If aria2c can't fetch the metadata within a reasonable time, the swarm may be empty or the peers may not support BEP 9 (the metadata exchange extension). Try:

  • Using a different tracker URL
  • Trying again later when more peers might be online
  • Finding the torrent file directly on the original index site

DHT Is Blocked

Some networks (corporate, university, or certain ISPs) block DHT traffic. In that case, you'll need trackers to find peers. Make sure your magnet link includes at least one reliable tracker URL.

aria2c Not Found

If the aria2c command is not available after installation, ensure the installation directory is in your PATH. On some systems, you may need to start a new terminal session after installing.

Which Method Should You Choose?

Here's a quick comparison across the factors that matter most — privacy, ease of use, and reliability — to help you decide which approach fits your needs:

Factoraria2crqbit CLIHash2TorrentGUI ClientOnline Service
Privacy★★★ Local★★★ Local★★ Self-host / ★ Demo★★★ Local★ Reveals infohash
Installation★★★ apt install aria2★★ cargo install rqbit★ Needs server setup★★★ Download installer★★★ Nothing needed
Cross-platform★★★ All three★★★ All three★★ Docker / Rust★★★ All three★★★ Browser
Scriptability★★★ One-liner★★★ CLI + HTTP API★★★ HTTP API★ Manual clicks★★★ curl
Reliability★★★ Mature, active★★★ Active dev★★ Demo paused★★★ Mature★ Come and go
Dependencies★★★ Single binary★★ Rust toolchain★ Full server stack★★ Full desktop app★★★ None
Learning curve★★★ 1 command★★★ 1 command★★ Run a server★★★ Point & click★★★ Paste & download
Metadata-only★★★ Yes (--bt-metadata-only)★★★ Yes★★★ Yes★★ Downloads content★★★ Yes

Conclusion

Converting a magnet link or infohash into a .torrent file is a common task in the BitTorrent ecosystem, and as we've seen, there are multiple ways to do it. The underlying mechanism is always the same: the infohash is used to discover peers via DHT or trackers, and the metadata is fetched from those peers using BEP 9.

Our top recommendation is aria2c — it's fast, works everywhere, and the command is simple enough to remember or script. For infohashes, just construct a magnet link first, then apply the same aria2c command.

Whether you need the .torrent file for archiving, sharing, or inspection, these methods will get you there. And the next time someone shares a bare infohash with you, you'll know exactly what to do.

Want to learn more? Check out our other articles on BitTorrent technology, including Hash2Torrent — Retrieve Torrent Files Effortlessly!, What Is a BitTorrent Tracker?, and Torrust: Enhancing the BitTorrent Ecosystem.

Resources