🎉 Cmdop v1.0 is here! Download now →
Skip to Content

Files API

Read, write, and manage files on remote machines.

List Directory

GET /machines/:id/files

Query Parameters

ParameterTypeDescription
pathstringDirectory path (default: home)
hiddenbooleanInclude 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/content

Query Parameters

ParameterTypeDescription
pathstringFile 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/content

Request 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/upload

Request

Multipart form data:

  • path: Destination path
  • file: 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/download

Query Parameters

ParameterTypeDescription
pathstringFile path (required)

Returns file content with appropriate Content-Type header.

Delete File

DELETE /machines/:id/files

Query Parameters

ParameterTypeDescription
pathstringFile/directory path
recursivebooleanDelete directories recursively

Response

{ "data": { "deleted": true, "path": "/tmp/test.txt" } }

Create Directory

POST /machines/:id/files/mkdir

Request Body

{ "path": "/tmp/new-directory", "mode": "0755" }

Move/Rename

POST /machines/:id/files/move

Request Body

{ "source": "/tmp/old-name.txt", "destination": "/tmp/new-name.txt" }

Copy

POST /machines/:id/files/copy

Request Body

{ "source": "/tmp/original.txt", "destination": "/tmp/copy.txt" }

Files API | Cmdop