File Management
File Management
Upload and Download Files (Sync)
You can upload files to a running instance and download files from it using the sync API.
- Python
- TypeScript
- CLI
from morphcloud.api import MorphCloudClient
client = MorphCloudClient()
instance_id = "instance_your_instance_id" # Replace with a valid instance ID
instance = client.instances.get(instance_id=instance_id)
# Upload a local file to the instance
instance.upload(source_path="/local/path/to/file.txt", target_path="/remote/path/on/instance/file.txt")
# Download a file from the instance to your local machine
instance.download(source_path="/remote/path/on/instance/file.txt", target_path="/local/path/to/download.txt")
import { MorphCloudClient } from 'morphcloud'; // adjust import path if needed
const client = new MorphCloudClient();
async function syncFiles() {
const instance_id = "instance_your_instance_id"; // Replace with a valid instance ID
const instance = await client.instances.get({ instance_id: instance_id });
// Upload a local file to the instance
await instance.upload({
sourcePath: "/local/path/to/file.txt",
targetPath: "/remote/path/on/instance/file.txt"
});
// Download a file from the instance to your local machine
await instance.download({
sourcePath: "/remote/path/on/instance/file.txt",
targetPath: "/local/path/to/download.txt"
});
}
syncFiles();
# Upload a file to the instance
morphcloud instance upload instance_your_instance_id /local/path/to/file.txt /remote/path/on/instance/file.txt
# Download a file from the instance
morphcloud instance download instance_your_instance_id /remote/path/on/instance/file.txt /local/path/to/download.txt
Multi-File Transfer
For transferring multiple files, use the directory sync operations.
- Python
- TypeScript
- CLI
from morphcloud.api import MorphCloudClient
client = MorphCloudClient()
instance_id = "instance_your_instance_id" # Replace with a valid instance ID
instance = client.instances.get(instance_id=instance_id)
# Upload a directory to the instance (recursive by default)
instance.upload_dir(source_path="/local/directory", target_path="/remote/directory")
# Download a directory from the instance (recursive by default)
instance.download_dir(source_path="/remote/directory", target_path="/local/download_dir")
import { MorphCloudClient } from 'morphcloud'; // adjust import path if needed
const client = new MorphCloudClient();
async function syncDirectories() {
const instance_id = "instance_your_instance_id"; // Replace with a valid instance ID
const instance = await client.instances.get({ instance_id: instance_id });
// Upload a directory to the instance (recursive by default)
await instance.uploadDir({
sourcePath: "/local/directory",
targetPath: "/remote/directory"
});
// Download a directory from the instance (recursive by default)
await instance.downloadDir({
sourcePath: "/remote/directory",
targetPath: "/local/download_dir"
});
}
syncDirectories();
# Upload a directory to the instance
morphcloud instance upload-dir instance_your_instance_id /local/directory /remote/directory
# Download a directory from the instance
morphcloud instance download-dir instance_your_instance_id /remote/directory /local/download_dir
# Use the --recursive=false flag to disable recursive transfers
morphcloud instance upload-dir instance_your_instance_id --recursive=false /local/directory /remote/directory