Files API
Read, write, and manage files on remote machines.
List Directory
GET /machines/:id/filesQuery Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Directory path (default: home) |
hidden | boolean | Include hidden files |
Example
curl "https://api.cmdop.com/v1/machines/mach_abc123/files?path=/var/log" \
-H "Authorization: Bearer TOKEN"Response
{
"data": {
"path": "/var/log",
"files": [
{
"name": "syslog",
"path": "/var/log/syslog",
"type": "file",
"size": 1048576,
"mode": "0644",
"owner": "syslog",
"group": "adm",
"modified_at": "2024-01-20T15:45:00Z"
},
{
"name": "nginx",
"path": "/var/log/nginx",
"type": "directory",
"mode": "0755",
"owner": "root",
"group": "root",
"modified_at": "2024-01-20T12:00:00Z"
}
]
}
}Read File
GET /machines/:id/files/contentQuery Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | File path (required) |
Example
curl "https://api.cmdop.com/v1/machines/mach_abc123/files/content?path=/etc/nginx/nginx.conf" \
-H "Authorization: Bearer TOKEN"Response
{
"data": {
"path": "/etc/nginx/nginx.conf",
"content": "user nginx;\nworker_processes auto;\n...",
"size": 1234,
"encoding": "utf-8"
}
}Write File
PUT /machines/:id/files/contentRequest Body
{
"path": "/tmp/test.txt",
"content": "Hello, World!",
"mode": "0644"
}Response
{
"data": {
"path": "/tmp/test.txt",
"size": 13,
"created": true
}
}Upload File
POST /machines/:id/files/uploadRequest
Multipart form data:
path: Destination pathfile: File content
Example
curl -X POST "https://api.cmdop.com/v1/machines/mach_abc123/files/upload" \
-H "Authorization: Bearer TOKEN" \
-F "path=/tmp/upload.txt" \
-F "[email protected]"Download File
GET /machines/:id/files/downloadQuery Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | File path (required) |
Returns file content with appropriate Content-Type header.
Delete File
DELETE /machines/:id/filesQuery Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | File/directory path |
recursive | boolean | Delete directories recursively |
Response
{
"data": {
"deleted": true,
"path": "/tmp/test.txt"
}
}Create Directory
POST /machines/:id/files/mkdirRequest Body
{
"path": "/tmp/new-directory",
"mode": "0755"
}Move/Rename
POST /machines/:id/files/moveRequest Body
{
"source": "/tmp/old-name.txt",
"destination": "/tmp/new-name.txt"
}Copy
POST /machines/:id/files/copyRequest Body
{
"source": "/tmp/original.txt",
"destination": "/tmp/copy.txt"
}