write_file
Write content to a remote file over SSH, with support for sudo or SFTP, configurable encoding, appending, directory creation, and permissions.
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 | ||
| remote_path | Yes | ||
| content | Yes | ||
| username | No | ||
| password | No | ||
| key_filename | No | ||
| port | No | ||
| encoding | No | utf-8 | |
| errors | No | strict | |
| append | No | ||
| make_dirs | No | ||
| permissions | No | ||
| max_bytes | No | ||
| sudo_password | No | ||
| use_sudo | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |