# Tunnel task

A Tunnel task opens a CrushMFT tunnel to another CrushMFT server, or closes one. A tunnel carries a network connection inside the server's ordinary HTTPS port: a job can so reach a database, a mail server or any other service that sits behind the other server and has no way in of its own.

Tunnels are set up on the server that is tunnelled **to**, for a user there: see [Port forwarding and tunnels](Ports-Port-Forward.md). This task is the other end. It opens and closes the tunnel; it does not itself send a file through it, as the task picker's line has it.

## Fields

| Field | What it does |
|---|---|
| **Tunnel Action** | **Start** or **Stop** |
| **Tunnel Name** | the name of the tunnel, as it is set up for the user on the other server. Also the name under which this run remembers it. |
| **Server URL** | the other CrushMFT server: `https://files.partner.example/`. "Only http and https urls allowed." |
| **HTTP Username**, **HTTP Password** | the user on the other server to whom the tunnel belongs |

All fields take [variables](Jobs-Variables.md).

## How it is used

A tunnel has a local port, given in its setup. While the tunnel is open, a connection to `127.0.0.1` on that port comes out at the other end, at the host and port the tunnel names.

| Task | Does |
|---|---|
| **Tunnel**, Start, `to-warehouse-db` | logs in at the other server and opens the tunnel |
| the work | an [SQL](Task-SQL.md) task with the address `jdbc:…//127.0.0.1:15432/…`, or a Copy to `sftp://user@127.0.0.1:2022/` |
| **Tunnel**, Stop, `to-warehouse-db` | closes it |

Start → Tunnel (Start) → the work → Tunnel (Stop) → End.

- A second **Start** of the same name in one run does nothing: "Tunnel … already exists".
- A tunnel that the user on the other server does not have fails the task: "Tunnel … not found!".
- A tunnel that is not stopped is closed when the run ends.

## What it hands on

The items it was given, unchanged.

## Things to know

- **Lead the failure line to the Stop too**, so that a tunnel is not left open for the rest of a long run after the work in it failed.
- **One tunnel, one port.** Two runs of the job at once would both want the tunnel's local port. Tick **Single instance only** in the job's Setup.
- **Where the port is.** The tunnel's local port opens on the machine the run executes on. With [engines on other machines](Jobs-Engines-Other-Machines.md), that is the engine's machine, and `127.0.0.1` in the following tasks means that machine as well: both fit together as long as the whole run stays on one engine.
- **The password** is stored encrypted in the job.
- **Not for limited admins** unless their role names the tunnels they may use: see [Who may see, change and run a job](Jobs-Access.md).
- **The log.** While a tunnel is open, the run's log gets a line a second, "(Tunnel is Active: Out=…, In=…)", with what went through. Keep tunnels open for the work and no longer.
