AsyncSSH exposes dynamic TCP forwarding through forward_socks(). An application with AsyncSSH already available can create a local SOCKS listener over an SSH connection:

import asyncio
import asyncssh

async def main():
    async with asyncssh.connect(
        'jump.example.net', username='operator'
    ) as connection:
        listener = await connection.forward_socks('127.0.0.1', 1080)
        await listener.wait_closed()

asyncio.run(main())

The SSH server and account are examples. Normal AsyncSSH host-key checking applies. The server must permit the requested TCP forwarding. For a command-line equivalent, OpenSSH’s local dynamic forward uses the same SSH-to-destination direction.

Local clients can now use 127.0.0.1:1080 as their SOCKS endpoint. Each SOCKS request supplies its destination; the SSH server opens the corresponding outgoing TCP connection. The application does not need to execute a remote downloader for every URL.

The wait keeps the asynchronous function inside the connection scope. Returning immediately after creating the listener would exit that scope and close the connection supporting it. A larger asyncio application can keep this connection open while running its other tasks on the same event loop.

Artiglyn mynjee