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

# Write File Contents

> Write or overwrite a file on the server

## Endpoint

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

## 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 write (relative to server root)
</ParamField>

## Request Body

Raw file contents to write. The `Content-Type` should be set appropriately for the file being written.

## Response

Returns `204 No Content` on success.

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://wings.example.com/api/servers/d3aac109-f0fc-4674-b5bc-199bb50e6b88/files/write?file=server.properties" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: text/plain" \
    -d "gamemode=survival
  difficulty=normal
  motd=My Minecraft Server"
  ```

  ```javascript JavaScript theme={null}
  const content = `gamemode=survival
  difficulty=normal
  motd=My Minecraft Server`;

  await fetch(
    'https://wings.example.com/api/servers/d3aac109-f0fc-4674-b5bc-199bb50e6b88/files/write?file=server.properties',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'text/plain'
      },
      body: content
    }
  );
  ```

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

  content = '''gamemode=survival
  difficulty=normal
  motd=My Minecraft Server'''

  requests.post(
      'https://wings.example.com/api/servers/d3aac109-f0fc-4674-b5bc-199bb50e6b88/files/write',
      params={'file': 'server.properties'},
      headers={'Authorization': 'Bearer YOUR_TOKEN'},
      data=content.encode('utf-8')
  )
  ```
</CodeGroup>

## Behavior

* Creates the file if it doesn't exist
* Overwrites the file completely if it already exists
* Creates parent directories automatically if they don't exist
* Sets appropriate file permissions based on server user configuration
* Path traversal is prevented
* Ignored files (`.pteroignore`) cannot be written

<Warning>
  This operation completely overwrites the target file. There is no backup or undo functionality.
</Warning>

## Error Responses

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

  <Accordion title="403 Forbidden">
    File is on the ignore list (.pteroignore) or path traversal attempt detected
  </Accordion>

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

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

## Use Cases

* Update configuration files
* Modify server settings
* Create new script files
* Edit whitelist/ban lists

## Source Reference

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