Skip to Content

Files API

TL;DR

The Files API enables reading, writing, uploading, downloading, and managing files on remote machines through CMDOP. List directory contents, read/write file content with encoding support, upload via multipart form data, download with streaming, and perform move/copy/delete operations. Supports file permissions and recursive directory deletion.

How do I list directory contents?

GET /machines/:id/files

What query parameters are supported for listing?

ParameterTypeDescription
pathstringDirectory path (default: home)
hiddenbooleanInclude hidden files

Example

# List files in /var/log on a remote machine 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" } ] } }

How do I read a file?

GET /machines/:id/files/content

What query parameters are required?

ParameterTypeDescription
pathstringFile path (required)

Example

# Read the contents of a remote configuration file 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" } }

How do I write a 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 } }

How do I upload a file?

POST /machines/:id/files/upload

Request

Multipart form data:

  • path: Destination path
  • file: File content

Example

# Upload a local file to a remote machine via multipart form data 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]"

How do I download a file?

GET /machines/:id/files/download

Query Parameters

ParameterTypeDescription
pathstringFile path (required)

Returns file content with appropriate Content-Type header.

How do I delete a file?

DELETE /machines/:id/files

What query parameters are supported for deletion?

ParameterTypeDescription
pathstringFile/directory path
recursivebooleanDelete directories recursively

Response

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

How do I create a directory?

POST /machines/:id/files/mkdir

Request Body

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

How do I move or rename a file?

POST /machines/:id/files/move

Request Body

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

How do I copy a file?

POST /machines/:id/files/copy

Request Body

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