# Import a server from another host

> Copy a server's files from another host over SFTP or FTP into your Coritan server with the Import tab.

Source: https://www.coritan.com/docs/managed-containers/import/

In the dashboard:

- /dashboard/servers/…/import: https://www.coritan.com/dashboard/servers

The **Import** tab copies a server's files from another host into your Coritan server over SFTP or FTP. Use it to bring a world, its plugins and its settings over from another hosting company. It copies files only, so the server's software stays as it is.

## Before you begin

- Get the file access details from the other host's panel: the address, the port, the username and the password for SFTP or FTP. FTPS is not supported: use SFTP, or plain FTP if the other host offers it.
- Check that the files fit. Everything in the folder you import must fit in this server's disk space.
- The folder you import can hold at most 250,000 files and folders. For a larger tree, import one sub-folder at a time.
- The other host must be on a public address. We refuse private and local addresses.
- The server cannot be installing, moving to another machine or suspended.
- On a server someone shared with you, the owner must have given you the Files permission.

## Import the files

1. In the [dashboard](https://www.coritan.com/dashboard/servers), go to **Container Apps** and open the server, then the **Import** tab.
2. Under **Protocol**, choose **SFTP** or **FTP**.
3. In **Host**, enter the other host's address, for example `sftp.example.com`.
4. In **Port**, enter the port the other host gave you. Leave it empty for the usual port: 22 for SFTP and 21 for FTP.
5. Enter the **Username** and **Password** from the other host.
6. In **Remote folder**, enter the folder whose contents should land in this server's root folder. `/` copies everything the account can see. If the other host keeps the server in `/minecraft`, enter `/minecraft`, and `/minecraft/world` becomes `/world` here.
7. To delete every file on this server before copying, tick **Wipe this server first**. Leave it clear to keep the files that are already here.
8. Select **Test connection**. We sign in and count what we would copy, without writing anything. **Connected** shows how many files and folders the remote folder holds.
9. Select **Start import**. If you ticked **Wipe this server first**, the button reads **Wipe and import…**: type the server's name to confirm, then select **Wipe and import**.

The **Import in progress** card shows the status, a meter with the files and bytes copied so far, and the file being copied. You can leave the page: the import carries on, and the tab shows it again when you come back.

## What the import does

- If the server is running, we stop it before copying and leave it stopped.
- With **Wipe this server first**, we delete every file on the server first.
- We copy every file and folder under the remote folder, empty folders included. A file with the same path as one on the server replaces it, and files that exist only on this server stay.
- We skip any single file that is larger than the server's whole disk space, and list it as a file we could not copy.
- On a free server, we keep the server program we installed and skip any file from the other host that would replace it.
- If the connection drops, we reconnect and carry on where the copy stopped.

The import fails if it runs for more than 6 hours, or once 200 files could not be copied.

## Stop an import

1. On the **Import in progress** card, select **Stop import…**.
2. Select **Stop import** to confirm.

The status reads `Stopping` until the copy halts, then `Cancelled`. Files the import already copied stay on the server. A server runs one import at a time, so stop the running one before you start another.

## Result

The status moves from `Queued` to `Copying`, then to `Completed`, `Failed` or `Cancelled`. When it completes, the card says `Import finished. Check the Files tab, then start the server.` If any files could not be copied, the card lists each one with its reason.

Check the files on the [Files tab](/docs/managed-containers/files/), then start the server from the [console](/docs/managed-containers/console/). If the other host ran different software or a different version, [change the server software](/docs/managed-containers/software/) to match before you start it. Select **Dismiss** to hide the card of a finished import.

## Troubleshooting

**Could not connect**
: The test failed, and the message under it gives the reason. Check the host, port, username and password against the other host's panel. Many game hosts use a port other than 22 for SFTP.

`Remote listing timed out`
: The test lists the remote folder for up to 60 seconds, and a large folder can take longer. Start the import anyway: the import itself allows 10 minutes to list the folder.

`FTPS is not supported; use SFTP, or plain FTP if the other host offers it`
: The address starts with `ftps://`. Use the other host's SFTP details instead.

`Could not reach sftp.example.com:22: connection timed out`
: We could not open a connection. Check the address and port, and that the other host allows connections from outside.

`Unable to resolve hostname: sftp.example.com`
: The address does not exist. Check its spelling.

`resolved address targets a private or reserved network`
: The address points at a private network, which we cannot reach. Use the other host's public address.

`The remote folder holds more than 250,000 files and folders; the importer copies at most that many. Import a sub-folder instead.`
: Import the folder in parts, one sub-folder at a time, with **Remote folder** set to each.

`The remote folder holds … but this server has … of disk`
: The files do not fit. Import less, or move to a plan with more disk.

`Cannot import while the server is installing`
: Wait until the installation finishes, then start the import. The same message names a server that is suspended or moving.

`An import is already running on this server`
: The tab shows the running import. Wait for it to finish, or stop it first.

`Stopped after 200 files could not be copied`
: The other host refused to send many files. Read the reasons in the list, fix the file permissions on the other host, and import again.

`Import timed out`
: The import ran for more than 6 hours. Import the rest in parts, with **Remote folder** set to each sub-folder.

`Too many requests for this action. Please wait and try again.`
: You tested or started more than 12 imports on this server in 5 minutes. Wait a few minutes and try again.

## Related

- [Manage server files](/docs/managed-containers/files/)
- [Connect to a server with SFTP](/docs/managed-containers/sftp/) to upload files yourself instead.
- [Take a server snapshot](/docs/managed-containers/snapshots/) before you import over files you want to keep.

## With the API

The routes take the same body. `type` is `sftp` or `ftp`, `remote_host` is the address, `remote_port` defaults to 22 or 21, `username` and `password` are the other host's login, `base_path` is the remote folder (default `/`), and `truncate` set to `true` wipes the server first.

Test the connection with `POST /api/v1/client/servers/{uuid}/import/test-connection`:

```bash
curl -X POST https://api.coritan.com/api/v1/client/servers/$SERVER/import/test-connection \
  -H "Authorization: Bearer $CORITAN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type": "sftp", "remote_host": "sftp.example.com", "remote_port": 2022, "username": "alex", "password": "old-host-password", "base_path": "/minecraft"}'
```

It answers `{"success": true, "files": 1843, "directories": 212}`, or `success` set to `false` with a `message`. Send the same body to `POST /api/v1/client/servers/{uuid}/import/start` to start the import. It signs in to the other host first and answers `400` if that fails, so a wrong password never becomes a queued import.

The start route and the status routes return the import:

```json
{
  "import_id": "0b7f9c1e-5d2a-4f61-9a43-2c8e7d10b6a5",
  "status": "in_progress",
  "files_transferred": 412,
  "total_files": 1843,
  "bytes_transferred": 734003200,
  "total_bytes": 2147483648,
  "current_file": "/minecraft/world/region/r.0.0.mca",
  "errors": [],
  "cancel_requested": false,
  "truncate": false,
  "stopped_server": true
}
```

`status` is `pending`, `in_progress`, `cancelling`, `completed`, `failed` or `cancelled`. `errors` lists the files that could not be copied, each as `file` and `error`. `stopped_server` is `true` when we stopped the server for the import.

| Route | What it does |
|---|---|
| `GET /api/v1/client/servers/{uuid}/import/status/{import_id}` | Returns one import. |
| `GET /api/v1/client/servers/{uuid}/import/current` | Returns `{"import": …}` with the running import, or the last one if it finished in the past 24 hours, or `null`. |
| `DELETE /api/v1/client/servers/{uuid}/import/{import_id}` | Stops the import. One that has not begun is `cancelled` at once; one that is copying is `cancelling` until it halts. |

Starting an import while one runs answers `409` with `message`, `import_id` and `status` of the running one. Testing and starting share a limit of 12 requests per server in 5 minutes. Testing and reading need `file.read`, starting and stopping need `file.create`, and a start with `truncate` also needs `file.delete`.

## API

- `GET /api/v1/client/servers/{uuid}/import/current`: Active import, or a recently finished one, so a refresh can resume the UI (https://www.coritan.com/docs/api/reference/client/container-apps/servers-import/#op-get-api-v1-client-servers-uuid-import-current)
- `POST /api/v1/client/servers/{uuid}/import/start`: Queue a remote tree copy onto this server (https://www.coritan.com/docs/api/reference/client/container-apps/servers-import/#op-post-api-v1-client-servers-uuid-import-start)
- `GET /api/v1/client/servers/{uuid}/import/status/{import_id}`: Poll an import the caller started (https://www.coritan.com/docs/api/reference/client/container-apps/servers-import/#op-get-api-v1-client-servers-uuid-import-status-import-id)
- `POST /api/v1/client/servers/{uuid}/import/test-connection`: Probe a remote SFTP/FTP host and count files without writing anything (https://www.coritan.com/docs/api/reference/client/container-apps/servers-import/#op-post-api-v1-client-servers-uuid-import-test-connection)
- `DELETE /api/v1/client/servers/{uuid}/import/{import_id}`: Stop a pending or in-progress import (https://www.coritan.com/docs/api/reference/client/container-apps/servers-import/#op-delete-api-v1-client-servers-uuid-import-import-id)
