Skip to content

Latest commit

 

History

History
72 lines (59 loc) · 2.29 KB

README.md

File metadata and controls

72 lines (59 loc) · 2.29 KB

Filen Sync

A package to sync local and remote directories.

Contributors Forks Stargazers Issues License

Installation

  1. Install using NPM
npm install @filen/sync@latest
  1. Initialize sync pairs
import { FilenSDK } from "@filen/sdk"
import path from "path"
import os from "os"
import { SyncWorker } from "@filen/sync"

// Initialize a SDK instance (optional)
const filen = new FilenSDK({
	metadataCache: true,
	connectToSocket: true,
	tmpPath: path.join(os.tmpdir(), "filen-sdk")
})

await filen.login({
	email: "[email protected]",
	password: "supersecret123",
	twoFactorCode: "123456"
})

const sync = new SyncWorker({
	syncPairs: [
		{
			uuid: "UUIDV4", // Only used locally to identify the sync pair
			localPath: pathModule.join(__dirname, "sync"), // Local absolute path
			remotePath: "/sync", // Remote absolute path (UNIX style)
			remoteParentUUID: "UUIDV4", // UUIDv4 of the remote parent directory
			mode: "twoWay", // Sync mode
			paused: false, // Start paused
			excludeDotFiles: true, // Exclude dot files and paths
			localTrashDisabled: false, // Disable the local trash
			name: "Sync" // Only used locally to identify the sync pair
		}
	],
	sdk: filen, // You can either directly pass a configured FilenSDK instance or instantiate a new SDK instance when passing `sdkConfig` (optional)
	sdkConfig, // FilenSDK config object (omit when SDK instance is passed, needed when no SDK instance is passed)
	dbPath: pathModule.join(__dirname, "db"), // Used to store sync state and other data
	runOnce: false, // Run the sync once
	onMessage(message) {
		console.log(message.type)
	}
})

// Start the sync
await sync.initialize()

License

Distributed under the AGPL-3.0 License. See LICENSE for more information.