ssh_file_write
Creates, overwrites, or appends remote files over SSH while handling special characters and multiline content; set permissions and create parent directories.
Instructions
Create a new file, or overwrite/append to an existing one, with the given
content (works the same whether or not the file already exists - append=True
on a nonexistent file just creates it). Handles special characters and
multi-line content properly.
mode (Unix permission bits) is applied via a chmod command after writing -
this only works on Linux/macOS. On Windows there's no equivalent, so mode is
silently ignored there (same convention as ssh_dir_mkdir's mode parameter).
Returns:
On success: {'success': True, 'file_path', 'bytes_written' (int), 'mode' (octal string, or None if not set OR if the connection is Windows - the response never echoes back a mode value that wasn't actually applied), 'append' (bool, echoes the parameter), 'connection'}. On failure (e.g.
parent directory missing and create_dirs=False, write error):
{'success': False, 'file_path', 'error'} - not a raised exception.
Long-running calls: if this takes longer than the server's wait cap (default 50s), it
returns {"status": "in_progress", "handle_id": ...} instead of the result - the work keeps
running. Get the result by polling ssh_cmd_check_status(handle_id=...), which returns this
tool's normal response once finished. Do not call it again meanwhile. Only one such
operation runs at a time; another one started meanwhile fails with a 'busy' error.Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | File permissions to set after writing (octal, e.g. 0o644) | |
| append | No | Whether to append to the file instead of overwriting | |
| content | Yes | Content to write to the file | |
| use_sudo | No | Use sudo for the operation | |
| file_path | Yes | Path to the file to write to | |
| create_dirs | No | Create parent directories if they don't exist |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||