> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/pterodactyl/wings/llms.txt
> Use this file to discover all available pages before exploring further.

# Compress Files

> Create a compressed archive of files and directories

## Endpoint

```
POST /api/servers/:server/files/compress
```

## Authentication

Requires Bearer token authentication via the `Authorization` header.

## Path Parameters

<ParamField path="server" type="string" required>
  The UUID of the server
</ParamField>

## Request Body

<ParamField body="root" type="string" required>
  The root directory for compression operations (all paths are relative to this)
</ParamField>

<ParamField body="files" type="string[]" required>
  Array of file/directory paths to include in the archive (relative to root)
</ParamField>

## Response

Returns a JSON object with the created archive information.

<ResponseField name="file" type="object">
  Information about the created archive file

  <Expandable title="File Object">
    <ResponseField name="name" type="string">
      Name of the created archive file (e.g., "archive-2024-01-15-143022.tar.gz")
    </ResponseField>

    <ResponseField name="mode" type="string">
      Unix file mode
    </ResponseField>

    <ResponseField name="mode_bits" type="string">
      Unix file mode in octal
    </ResponseField>

    <ResponseField name="size" type="integer">
      Size of the archive in bytes
    </ResponseField>

    <ResponseField name="is_file" type="boolean">
      Always true for archives
    </ResponseField>

    <ResponseField name="is_symlink" type="boolean">
      Always false for archives
    </ResponseField>

    <ResponseField name="mimetype" type="string">
      MIME type (application/gzip)
    </ResponseField>

    <ResponseField name="created_at" type="string">
      ISO 8601 timestamp
    </ResponseField>

    <ResponseField name="modified_at" type="string">
      ISO 8601 timestamp
    </ResponseField>
  </Expandable>
</ResponseField>

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://wings.example.com/api/servers/d3aac109-f0fc-4674-b5bc-199bb50e6b88/files/compress" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "root": "/",
      "files": ["world", "world_nether", "world_the_end"]
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://wings.example.com/api/servers/d3aac109-f0fc-4674-b5bc-199bb50e6b88/files/compress',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        root: '/',
        files: ['plugins/', 'config.yml', 'server.properties']
      })
    }
  );
  const result = await response.json();
  console.log('Archive created:', result.file.name);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://wings.example.com/api/servers/d3aac109-f0fc-4674-b5bc-199bb50e6b88/files/compress',
      headers={'Authorization': 'Bearer YOUR_TOKEN'},
      json={
          'root': '/backups',
          'files': ['world-2024-01-15/']
      }
  )
  archive_info = response.json()
  print(f"Created: {archive_info['file']['name']}")
  ```
</CodeGroup>

## Example Response

```json theme={null}
{
  "file": {
    "name": "archive-2024-01-15-143022.tar.gz",
    "mode": "-rw-r--r--",
    "mode_bits": "0644",
    "size": 52428800,
    "is_file": true,
    "is_symlink": false,
    "mimetype": "application/gzip",
    "created_at": "2024-01-15T14:30:22Z",
    "modified_at": "2024-01-15T14:30:22Z"
  }
}
```

## Behavior

* Creates a gzip-compressed tar archive (`.tar.gz`)
* Archive is created in the specified `root` directory
* Filename format: `archive-YYYY-MM-DD-HHMMSS.tar.gz`
* Both files and directories can be compressed
* Directories are archived recursively
* Preserves file permissions and timestamps
* Symlinks are followed and their targets are archived
* Path traversal is prevented

<Info>
  The compression operation runs asynchronously. The response is returned immediately with the expected archive information, but the actual compression may take some time for large datasets.
</Info>

## Error Responses

<AccordionGroup>
  <Accordion title="401 Unauthorized">
    Missing or invalid Bearer token
  </Accordion>

  <Accordion title="404 Not Found">
    Server does not exist or source files not found
  </Accordion>

  <Accordion title="500 Internal Server Error">
    Failed to create archive (disk full, permission error, etc.)
  </Accordion>
</AccordionGroup>

## Use Cases

* Create backups of world files
* Archive old logs
* Package plugins for transfer
* Create downloadable server snapshots
* Prepare files for export

## Source Reference

Implementation: `router/router_server_files.go` (postServerCompressFiles function)
