write_file
Writes content to a remote file over SSH, with sudo for privileged writes, SFTP fallback, append mode, and directory creation.
Instructions
Write content to a remote file over SSH.
If use_sudo is True or sudo_password is provided, uses sudo via shell commands (tee). Otherwise, attempts to write using SFTP.
Args: host: Hostname, IP address, or SSH config alias remote_path: Path to the remote file content: Content to write username: SSH username (optional) password: SSH password (optional) key_filename: Path to SSH key file (optional) port: SSH port (optional) encoding: Text encoding (default: utf-8) errors: Error handling for encoding (default: strict) append: Append to file instead of overwriting (default: False) make_dirs: Create parent directories if they don't exist (default: False) permissions: Octal file permissions to set (e.g., 420 for 0644) max_bytes: Maximum bytes to write (default: 2MB) sudo_password: Password for sudo (optional, not needed if NOPASSWD configured) use_sudo: Use sudo for writing (tries passwordless if no sudo_password provided)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | Yes | ||
| port | No | ||
| append | No | ||
| errors | No | strict | |
| content | Yes | ||
| encoding | No | utf-8 | |
| password | No | ||
| use_sudo | No | ||
| username | No | ||
| make_dirs | No | ||
| max_bytes | No | ||
| permissions | No | ||
| remote_path | Yes | ||
| key_filename | No | ||
| sudo_password | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |