> ## 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.

# Read File Contents

> Read the contents of a file on the server

## Endpoint

```
GET /api/servers/:server/files/contents
```

## Authentication

Requires Bearer token authentication via the `Authorization` header.

## Path Parameters

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

## Query Parameters

<ParamField query="file" type="string" required>
  The file path to read (relative to server root)
</ParamField>

<ParamField query="download" type="string">
  If present (any value), the response will include download headers
</ParamField>

## Response

Returns the raw file contents with appropriate headers.

### Response Headers

* `X-Mime-Type`: Detected MIME type of the file
* `Content-Length`: Size of the file in bytes
* `Content-Disposition`: Set to `attachment` if `download` parameter is present
* `Content-Type`: Set to `application/octet-stream` for downloads, otherwise the file's MIME type

## Example Request

<CodeGroup>
  ```bash cURL - View File theme={null}
  curl -X GET "https://wings.example.com/api/servers/d3aac109-f0fc-4674-b5bc-199bb50e6b88/files/contents?file=server.properties" \
    -H "Authorization: Bearer YOUR_TOKEN"
  ```

  ```bash cURL - Download File theme={null}
  curl -X GET "https://wings.example.com/api/servers/d3aac109-f0fc-4674-b5bc-199bb50e6b88/files/contents?file=world.zip&download=true" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -o world.zip
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://wings.example.com/api/servers/d3aac109-f0fc-4674-b5bc-199bb50e6b88/files/contents?file=config.yml',
    {
      headers: {
        'Authorization': 'Bearer YOUR_TOKEN'
      }
    }
  );
  const contents = await response.text();
  ```

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

  response = requests.get(
      'https://wings.example.com/api/servers/d3aac109-f0fc-4674-b5bc-199bb50e6b88/files/contents',
      params={'file': 'server.properties'},
      headers={'Authorization': 'Bearer YOUR_TOKEN'}
  )
  contents = response.text
  ```
</CodeGroup>

## Behavior

* Leading slashes in the file path are automatically stripped
* Named pipes cannot be opened (returns 400 error)
* File size is determined at request time and a limited reader prevents content overflow
* Path traversal is prevented - files outside the server directory cannot be accessed

<Warning>
  If the file is modified while being read, you may receive partial or inconsistent content based on the file size at the time the request started.
</Warning>

## Error Responses

<AccordionGroup>
  <Accordion title="400 Bad Request">
    File is a named pipe or another unsupported file type
  </Accordion>

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

  <Accordion title="404 Not Found">
    Server or file does not exist
  </Accordion>

  <Accordion title="500 Internal Server Error">
    Failed to read file contents
  </Accordion>
</AccordionGroup>

## Use Cases

* View configuration files
* Read log files
* Download world/map files
* Inspect server data files

## Source Reference

Implementation: `router/router_server_files.go:30-75`
