scp-next 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +403 -0
- package/dist/cli/index.js +1294 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.cjs +828 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +180 -0
- package/dist/index.d.ts +180 -0
- package/dist/index.js +778 -0
- package/dist/index.js.map +1 -0
- package/docs/ARCHITECTURE.md +55 -0
- package/package.json +86 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client/client.ts","../src/client/transport.ts","../src/security/redact.ts","../src/errors/index.ts","../src/security/host-verification.ts","../src/paths/local-path.ts","../src/client/walk.ts","../src/paths/remote-path.ts","../src/config/validation.ts","../src/client/upload.ts","../src/client/download.ts","../src/client/copy.ts"],"sourcesContent":["import { access, mkdir } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport { Ssh2SftpTransport } from \"./transport.js\";\nimport type { SftpTransport } from \"./transport.js\";\nimport { walkLocalFiles, walkRemoteFiles } from \"./walk.js\";\nimport { TransferError, ValidationError } from \"../errors/index.js\";\nimport { getLocalPathKind, resolveLocalPath } from \"../paths/local-path.js\";\nimport { normalizeRemotePath, remoteDirname, remoteJoin } from \"../paths/remote-path.js\";\nimport type {\n DownloadOptions,\n ScpNextClient,\n ScpServerOptions,\n TransferOptions,\n UploadOptions\n} from \"../types/index.js\";\nimport {\n validateDownloadOptions,\n validateServerOptions,\n validateUploadOptions\n} from \"../config/validation.js\";\n\nexport interface ScpNextClientDependencies {\n transport?: SftpTransport;\n}\n\nfunction percentage(transferredBytes: number, totalBytes?: number): number | undefined {\n if (!totalBytes || totalBytes <= 0) {\n return undefined;\n }\n return Math.min(100, Math.round((transferredBytes / totalBytes) * 100));\n}\n\nfunction mergeOptions<T extends TransferOptions>(\n serverOptions: ScpServerOptions,\n transferOptions: T | undefined\n): ScpServerOptions & T {\n return { ...serverOptions, ...(transferOptions ?? {}) } as ScpServerOptions & T;\n}\n\nexport class ScpNextClientImpl implements ScpNextClient {\n private readonly serverOptions: ScpServerOptions;\n private readonly transport: SftpTransport;\n private connected = false;\n\n constructor(serverOptions: ScpServerOptions, dependencies: ScpNextClientDependencies = {}) {\n this.serverOptions = serverOptions;\n this.transport = dependencies.transport ?? new Ssh2SftpTransport();\n }\n\n async connect(): Promise<void> {\n await validateServerOptions(this.serverOptions);\n await this.transport.connect(this.serverOptions);\n this.connected = true;\n }\n\n async upload(\n localPath: string,\n remotePath: string,\n options: TransferOptions = {}\n ): Promise<void> {\n const uploadOptions: UploadOptions = {\n ...mergeOptions(this.serverOptions, options),\n localPath,\n remotePath\n };\n await validateUploadOptions(uploadOptions);\n\n if (options.dryRun) {\n return;\n }\n\n await this.ensureConnected();\n await this.uploadWithTransport(uploadOptions);\n }\n\n async download(\n remotePath: string,\n localPath: string,\n options: TransferOptions = {}\n ): Promise<void> {\n const downloadOptions: DownloadOptions = {\n ...mergeOptions(this.serverOptions, options),\n remotePath,\n localPath\n };\n await validateDownloadOptions(downloadOptions);\n\n if (options.dryRun) {\n return;\n }\n\n await this.ensureConnected();\n await this.downloadWithTransport(downloadOptions);\n }\n\n async close(): Promise<void> {\n if (this.connected) {\n await this.transport.close();\n this.connected = false;\n }\n }\n\n private async ensureConnected(): Promise<void> {\n if (!this.connected) {\n await this.connect();\n }\n }\n\n private async uploadWithTransport(options: UploadOptions): Promise<void> {\n const localKind = await getLocalPathKind(options.localPath);\n const remotePath = normalizeRemotePath(options.remotePath);\n\n if (localKind === \"directory\" && !options.recursive) {\n throw new ValidationError(\"Uploading a directory requires recursive mode.\");\n }\n\n if (localKind === \"file\") {\n await this.ensureRemoteParent(remotePath, options.createDirectories);\n await this.assertRemoteOverwrite(remotePath, options.overwrite);\n const totalBytes = undefined;\n await this.transport.uploadFile(resolveLocalPath(options.localPath), remotePath, (step) => {\n options.onProgress?.({\n operation: \"upload\",\n source: options.localPath,\n destination: options.remotePath,\n transferredBytes: step.transferredBytes,\n totalBytes: step.totalBytes || totalBytes,\n percentage: percentage(step.transferredBytes, step.totalBytes),\n currentFile: options.localPath\n });\n });\n return;\n }\n\n const files = await walkLocalFiles(options.localPath);\n const totalBytes = files.reduce((sum, file) => sum + file.size, 0);\n let completedBytes = 0;\n let completedFiles = 0;\n\n const destinationExists = await this.transport.exists(remotePath);\n if (destinationExists && destinationExists !== \"d\") {\n throw new TransferError(`Remote destination already exists and is not a directory: ${remotePath}`, {\n context: { remotePath }\n });\n }\n if (!destinationExists) {\n if (!options.createDirectories) {\n throw new TransferError(`Remote destination directory does not exist: ${remotePath}`, {\n context: { remotePath }\n });\n }\n await this.transport.mkdir(remotePath, true);\n }\n\n for (const file of files) {\n const destinationFile = remoteJoin(remotePath, file.relativePath.split(path.sep).join(\"/\"));\n await this.ensureRemoteParent(destinationFile, true);\n await this.assertRemoteOverwrite(destinationFile, options.overwrite);\n\n await this.transport.uploadFile(file.absolutePath, destinationFile, (step) => {\n const transferredBytes = completedBytes + step.transferredBytes;\n options.onProgress?.({\n operation: \"upload\",\n source: options.localPath,\n destination: options.remotePath,\n transferredBytes,\n totalBytes,\n percentage: percentage(transferredBytes, totalBytes),\n currentFile: file.relativePath,\n completedFiles,\n totalFiles: files.length\n });\n });\n\n completedBytes += file.size;\n completedFiles += 1;\n }\n }\n\n private async downloadWithTransport(options: DownloadOptions): Promise<void> {\n const remotePath = normalizeRemotePath(options.remotePath);\n const remoteKind = await this.transport.exists(remotePath);\n\n if (!remoteKind) {\n throw new TransferError(`Remote path does not exist: ${options.remotePath}`, {\n context: { remotePath: options.remotePath }\n });\n }\n\n if (remoteKind === \"d\") {\n if (!options.recursive) {\n throw new ValidationError(\"Downloading a directory requires recursive mode.\");\n }\n await this.downloadDirectory(options);\n return;\n }\n\n await this.downloadSingleFile(options, remotePath);\n }\n\n private async downloadSingleFile(options: DownloadOptions, remotePath: string): Promise<void> {\n const localPath = resolveLocalPath(options.localPath);\n await this.assertLocalOverwrite(localPath, options.overwrite);\n if (options.createDirectories) {\n await mkdir(path.dirname(localPath), { recursive: true });\n }\n await this.transport.downloadFile(remotePath, localPath, (step) => {\n options.onProgress?.({\n operation: \"download\",\n source: options.remotePath,\n destination: options.localPath,\n transferredBytes: step.transferredBytes,\n totalBytes: step.totalBytes,\n percentage: percentage(step.transferredBytes, step.totalBytes),\n currentFile: options.remotePath\n });\n });\n }\n\n private async downloadDirectory(options: DownloadOptions): Promise<void> {\n const remotePath = normalizeRemotePath(options.remotePath);\n const localRoot = resolveLocalPath(options.localPath);\n const files = await walkRemoteFiles(this.transport, remotePath);\n const totalBytes = files.reduce((sum, file) => sum + file.size, 0);\n let completedBytes = 0;\n let completedFiles = 0;\n\n await mkdir(localRoot, { recursive: Boolean(options.createDirectories) });\n\n for (const file of files) {\n const localFile = path.join(localRoot, ...file.relativePath.split(\"/\"));\n await this.assertLocalOverwrite(localFile, options.overwrite);\n await mkdir(path.dirname(localFile), { recursive: true });\n await this.transport.downloadFile(file.remotePath, localFile, (step) => {\n const transferredBytes = completedBytes + step.transferredBytes;\n options.onProgress?.({\n operation: \"download\",\n source: options.remotePath,\n destination: options.localPath,\n transferredBytes,\n totalBytes,\n percentage: percentage(transferredBytes, totalBytes),\n currentFile: file.relativePath,\n completedFiles,\n totalFiles: files.length\n });\n });\n completedBytes += file.size;\n completedFiles += 1;\n }\n }\n\n private async ensureRemoteParent(remotePath: string, createDirectories = false): Promise<void> {\n const parent = remoteDirname(remotePath);\n if (parent === \".\" || parent === \"/\") {\n return;\n }\n\n if (createDirectories) {\n await this.transport.mkdir(parent, true);\n return;\n }\n\n const exists = await this.transport.exists(parent);\n if (exists !== \"d\") {\n throw new TransferError(`Remote destination parent does not exist: ${parent}`, {\n context: { remotePath }\n });\n }\n }\n\n private async assertRemoteOverwrite(remotePath: string, overwrite = false): Promise<void> {\n if (overwrite) {\n return;\n }\n const exists = await this.transport.exists(remotePath);\n if (exists) {\n throw new TransferError(`Remote destination already exists: ${remotePath}`, {\n context: { remotePath }\n });\n }\n }\n\n private async assertLocalOverwrite(localPath: string, overwrite = false): Promise<void> {\n if (overwrite) {\n return;\n }\n\n try {\n await access(localPath);\n throw new TransferError(`Local destination already exists: ${localPath}`, {\n context: { localPath }\n });\n } catch (error) {\n if (error instanceof TransferError) {\n throw error;\n }\n }\n }\n}\n\nexport function createClient(options: ScpServerOptions): ScpNextClient {\n return new ScpNextClientImpl(options);\n}\n","import { readFile } from \"node:fs/promises\";\n\nimport SftpClient from \"ssh2-sftp-client\";\nimport type {\n ConnectOptions as SftpConnectOptions,\n FileInfo,\n TransferOptions as SftpTransferOptions\n} from \"ssh2-sftp-client\";\n\nimport { ConnectionError, HostVerificationError, TransferError, toScpNextError } from \"../errors/index.js\";\nimport { createHostVerifier, resolveAllowedFingerprints } from \"../security/host-verification.js\";\nimport type { ScpServerOptions } from \"../types/index.js\";\nimport { expandHome } from \"../paths/local-path.js\";\n\nexport interface RemoteFileInfo {\n type: \"-\" | \"d\" | \"l\";\n name: string;\n size: number;\n}\n\nexport interface TransferStep {\n transferredBytes: number;\n chunkBytes: number;\n totalBytes: number;\n}\n\nexport interface SftpTransport {\n connect(options: ScpServerOptions): Promise<void>;\n close(): Promise<void>;\n exists(remotePath: string): Promise<false | \"-\" | \"d\" | \"l\">;\n mkdir(remotePath: string, recursive?: boolean): Promise<void>;\n list(remotePath: string): Promise<RemoteFileInfo[]>;\n uploadFile(\n localPath: string,\n remotePath: string,\n onStep?: (step: TransferStep) => void\n ): Promise<void>;\n downloadFile(\n remotePath: string,\n localPath: string,\n onStep?: (step: TransferStep) => void\n ): Promise<void>;\n}\n\nfunction toRemoteFileInfo(info: FileInfo): RemoteFileInfo {\n return {\n type: info.type,\n name: info.name,\n size: info.size\n };\n}\n\nexport class Ssh2SftpTransport implements SftpTransport {\n private readonly client: SftpClient;\n\n constructor(name = \"scp-next\") {\n this.client = new SftpClient(name);\n }\n\n async connect(options: ScpServerOptions): Promise<void> {\n const allowedFingerprints = await resolveAllowedFingerprints(options);\n const hostVerifier = createHostVerifier(allowedFingerprints);\n\n const connectOptions: SftpConnectOptions = {};\n if (options.host !== undefined) connectOptions.host = options.host;\n if (options.port !== undefined) connectOptions.port = options.port;\n if (options.username !== undefined) connectOptions.username = options.username;\n if (options.password !== undefined) connectOptions.password = options.password;\n if (options.privateKey !== undefined) {\n connectOptions.privateKey = options.privateKey;\n } else if (options.privateKeyFile) {\n connectOptions.privateKey = await readFile(expandHome(options.privateKeyFile), \"utf8\");\n }\n if (options.passphrase !== undefined) connectOptions.passphrase = options.passphrase;\n const agent = options.agent ?? process.env.SSH_AUTH_SOCK;\n if (agent !== undefined) {\n connectOptions.agent = agent;\n }\n if (options.timeout !== undefined) connectOptions.readyTimeout = options.timeout;\n if (hostVerifier) {\n connectOptions.hostHash = \"sha256\";\n connectOptions.hostVerifier = hostVerifier;\n }\n\n try {\n await this.client.connect(connectOptions);\n } catch (error) {\n const converted = toScpNextError(error);\n if (converted instanceof HostVerificationError) {\n throw converted;\n }\n throw new ConnectionError(\"Unable to connect to SSH server.\", {\n cause: error,\n context: {\n host: options.host,\n port: options.port,\n username: options.username\n }\n });\n }\n }\n\n async close(): Promise<void> {\n await this.client.end();\n }\n\n async exists(remotePath: string): Promise<false | \"-\" | \"d\" | \"l\"> {\n return this.client.exists(remotePath);\n }\n\n async mkdir(remotePath: string, recursive = true): Promise<void> {\n await this.client.mkdir(remotePath, recursive);\n }\n\n async list(remotePath: string): Promise<RemoteFileInfo[]> {\n const files = await this.client.list(remotePath);\n return files.map(toRemoteFileInfo);\n }\n\n async uploadFile(\n localPath: string,\n remotePath: string,\n onStep?: (step: TransferStep) => void\n ): Promise<void> {\n try {\n await this.client.fastPut(localPath, remotePath, this.transferOptions(onStep));\n } catch (error) {\n throw new TransferError(`Upload failed for ${localPath}.`, {\n cause: error,\n context: { localPath, remotePath }\n });\n }\n }\n\n async downloadFile(\n remotePath: string,\n localPath: string,\n onStep?: (step: TransferStep) => void\n ): Promise<void> {\n try {\n await this.client.fastGet(remotePath, localPath, this.transferOptions(onStep));\n } catch (error) {\n throw new TransferError(`Download failed for ${remotePath}.`, {\n cause: error,\n context: { remotePath, localPath }\n });\n }\n }\n\n private transferOptions(onStep?: (step: TransferStep) => void): SftpTransferOptions | undefined {\n if (!onStep) {\n return undefined;\n }\n return {\n step(transferredBytes, chunkBytes, totalBytes) {\n onStep({ transferredBytes, chunkBytes, totalBytes });\n }\n };\n }\n}\n","const SENSITIVE_KEYS = [\n \"password\",\n \"passphrase\",\n \"privatekey\",\n \"privatekeyfile\",\n \"token\",\n \"authorization\",\n \"credential\",\n \"secret\"\n];\n\nconst PRIVATE_KEY_PATTERN =\n /-----BEGIN [A-Z ]*PRIVATE KEY-----[\\s\\S]*?-----END [A-Z ]*PRIVATE KEY-----/g;\n\nfunction isSensitiveKey(key: string): boolean {\n const normalized = key.replace(/[-_\\s]/g, \"\").toLowerCase();\n return SENSITIVE_KEYS.some((sensitive) => normalized.includes(sensitive));\n}\n\nexport function redactSensitiveValues(value: unknown): unknown {\n if (typeof value === \"string\") {\n return value.replace(PRIVATE_KEY_PATTERN, \"[REDACTED]\");\n }\n\n if (Array.isArray(value)) {\n const redacted: unknown[] = value.map((item: unknown) => redactSensitiveValues(item));\n return redacted;\n }\n\n if (value && typeof value === \"object\") {\n const redacted: Record<string, unknown> = {};\n for (const [key, nestedValue] of Object.entries(value)) {\n redacted[key] = isSensitiveKey(key) ? \"[REDACTED]\" : redactSensitiveValues(nestedValue);\n }\n return redacted;\n }\n\n return value;\n}\n\nexport function formatErrorMessage(error: unknown): string {\n if (error instanceof Error) {\n return String(redactSensitiveValues(error.message));\n }\n return String(redactSensitiveValues(error));\n}\n","import { redactSensitiveValues } from \"../security/redact.js\";\n\nexport type ScpNextErrorCode =\n | \"SCP_NEXT_ERROR\"\n | \"SCP_NEXT_CONFIGURATION_ERROR\"\n | \"SCP_NEXT_VALIDATION_ERROR\"\n | \"SCP_NEXT_AUTHENTICATION_ERROR\"\n | \"SCP_NEXT_CONNECTION_ERROR\"\n | \"SCP_NEXT_TRANSFER_ERROR\"\n | \"SCP_NEXT_FILESYSTEM_ERROR\"\n | \"SCP_NEXT_HOST_VERIFICATION_ERROR\";\n\nexport interface ScpNextErrorOptions {\n code?: ScpNextErrorCode;\n cause?: unknown;\n context?: Record<string, unknown>;\n}\n\nexport class ScpNextError extends Error {\n readonly code: ScpNextErrorCode;\n readonly context: Record<string, unknown>;\n\n constructor(message: string, options: ScpNextErrorOptions = {}) {\n super(message, { cause: options.cause });\n this.name = new.target.name;\n this.code = options.code ?? \"SCP_NEXT_ERROR\";\n this.context = redactSensitiveValues(options.context ?? {}) as Record<string, unknown>;\n }\n}\n\nexport class ConfigurationError extends ScpNextError {\n constructor(message: string, options: Omit<ScpNextErrorOptions, \"code\"> = {}) {\n super(message, { ...options, code: \"SCP_NEXT_CONFIGURATION_ERROR\" });\n }\n}\n\nexport class ValidationError extends ScpNextError {\n constructor(message: string, options: Omit<ScpNextErrorOptions, \"code\"> = {}) {\n super(message, { ...options, code: \"SCP_NEXT_VALIDATION_ERROR\" });\n }\n}\n\nexport class AuthenticationError extends ScpNextError {\n constructor(message: string, options: Omit<ScpNextErrorOptions, \"code\"> = {}) {\n super(message, { ...options, code: \"SCP_NEXT_AUTHENTICATION_ERROR\" });\n }\n}\n\nexport class ConnectionError extends ScpNextError {\n constructor(message: string, options: Omit<ScpNextErrorOptions, \"code\"> = {}) {\n super(message, { ...options, code: \"SCP_NEXT_CONNECTION_ERROR\" });\n }\n}\n\nexport class TransferError extends ScpNextError {\n constructor(message: string, options: Omit<ScpNextErrorOptions, \"code\"> = {}) {\n super(message, { ...options, code: \"SCP_NEXT_TRANSFER_ERROR\" });\n }\n}\n\nexport class FileSystemError extends ScpNextError {\n constructor(message: string, options: Omit<ScpNextErrorOptions, \"code\"> = {}) {\n super(message, { ...options, code: \"SCP_NEXT_FILESYSTEM_ERROR\" });\n }\n}\n\nexport class HostVerificationError extends ScpNextError {\n constructor(message: string, options: Omit<ScpNextErrorOptions, \"code\"> = {}) {\n super(message, { ...options, code: \"SCP_NEXT_HOST_VERIFICATION_ERROR\" });\n }\n}\n\nexport function toScpNextError(error: unknown): ScpNextError {\n if (error instanceof ScpNextError) {\n return error;\n }\n\n const message = error instanceof Error ? error.message : \"Unexpected scp-next error.\";\n const lowerMessage = message.toLowerCase();\n\n if (lowerMessage.includes(\"authentication\") || lowerMessage.includes(\"permission denied\")) {\n return new AuthenticationError(\"SSH authentication failed.\", { cause: error });\n }\n\n if (lowerMessage.includes(\"host verification\") || lowerMessage.includes(\"host key\")) {\n return new HostVerificationError(\"SSH host verification failed.\", { cause: error });\n }\n\n if (\n lowerMessage.includes(\"timed out\") ||\n lowerMessage.includes(\"connection\") ||\n lowerMessage.includes(\"econn\")\n ) {\n return new ConnectionError(\"SSH connection failed.\", { cause: error });\n }\n\n return new TransferError(String(redactSensitiveValues(message)), { cause: error });\n}\n","import { createHash } from \"node:crypto\";\nimport { access, readFile } from \"node:fs/promises\";\n\nimport { HostVerificationError } from \"../errors/index.js\";\nimport { expandHome } from \"../paths/local-path.js\";\n\nfunction normalizeFingerprint(fingerprint: string): string {\n return fingerprint\n .trim()\n .replace(/^SHA256:/i, \"\")\n .replace(/^sha256:/i, \"\")\n .replace(/=+$/g, \"\");\n}\n\nexport function isFingerprintMatch(actual: string, expected: string): boolean {\n return normalizeFingerprint(actual) === normalizeFingerprint(expected);\n}\n\nexport interface HostVerifierConfig {\n host?: string | undefined;\n hostFingerprint?: string | undefined;\n knownHostsFile?: string | undefined;\n}\n\nexport async function resolveAllowedFingerprints(\n options: HostVerifierConfig\n): Promise<Set<string>> {\n const fingerprints = new Set<string>();\n const knownHostsFile = options.knownHostsFile ?? \"~/.ssh/known_hosts\";\n\n if (!options.host) {\n throw new HostVerificationError(\"A host is required for SSH host verification.\");\n }\n\n if (options.hostFingerprint) {\n fingerprints.add(normalizeFingerprint(options.hostFingerprint));\n }\n\n try {\n await access(expandHome(knownHostsFile));\n const content = await readFile(expandHome(knownHostsFile), \"utf8\");\n for (const line of content.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith(\"#\") || trimmed.startsWith(\"@\")) {\n continue;\n }\n\n const [hosts, algorithm, key] = trimmed.split(/\\s+/);\n if (!hosts || !algorithm || !key || !hosts.split(\",\").includes(options.host)) {\n continue;\n }\n\n const fingerprint = createHash(\"sha256\")\n .update(Buffer.from(key, \"base64\"))\n .digest(\"base64\")\n .replace(/=+$/g, \"\");\n fingerprints.add(fingerprint);\n }\n } catch (error) {\n if (options.knownHostsFile || !options.hostFingerprint) {\n throw new HostVerificationError(\n \"SSH host verification requires hostFingerprint or an accessible knownHostsFile.\",\n { cause: error, context: { knownHostsFile } }\n );\n }\n }\n\n if (fingerprints.size === 0) {\n throw new HostVerificationError(\n \"SSH host verification failed before connecting: no matching host fingerprint was configured.\"\n );\n }\n\n return fingerprints;\n}\n\nexport function createHostVerifier(allowedFingerprints: Set<string>) {\n return (hashedKey: string): boolean => {\n for (const expected of allowedFingerprints) {\n if (isFingerprintMatch(hashedKey, expected)) {\n return true;\n }\n }\n return false;\n };\n}\n","import { constants } from \"node:fs\";\nimport { access, mkdir, stat } from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nimport { FileSystemError, ValidationError } from \"../errors/index.js\";\n\nexport function expandHome(inputPath: string): string {\n if (inputPath === \"~\") {\n return os.homedir();\n }\n if (inputPath.startsWith(`~${path.sep}`) || inputPath.startsWith(\"~/\")) {\n return path.join(os.homedir(), inputPath.slice(2));\n }\n return inputPath;\n}\n\nexport function resolveLocalPath(inputPath: string, baseDir = process.cwd()): string {\n const expanded = expandHome(inputPath);\n return path.isAbsolute(expanded) ? path.normalize(expanded) : path.resolve(baseDir, expanded);\n}\n\nexport async function assertLocalPathExists(inputPath: string): Promise<void> {\n try {\n await access(resolveLocalPath(inputPath), constants.F_OK);\n } catch (error) {\n throw new FileSystemError(`Local path does not exist: ${inputPath}`, {\n cause: error,\n context: { path: inputPath }\n });\n }\n}\n\nexport async function assertLocalFileReadable(inputPath: string): Promise<void> {\n try {\n await access(resolveLocalPath(inputPath), constants.R_OK);\n } catch (error) {\n throw new FileSystemError(`Local file is not readable: ${inputPath}`, {\n cause: error,\n context: { path: inputPath }\n });\n }\n}\n\nexport async function assertDownloadDestination(inputPath: string, createDirectories = false) {\n const resolved = resolveLocalPath(inputPath);\n const parent = path.dirname(resolved);\n\n if (createDirectories) {\n await mkdir(parent, { recursive: true });\n return;\n }\n\n try {\n await access(parent, constants.W_OK);\n } catch (error) {\n throw new FileSystemError(`Local destination parent does not exist or is not writable: ${parent}`, {\n cause: error,\n context: { path: inputPath }\n });\n }\n}\n\nexport async function getLocalPathKind(inputPath: string): Promise<\"file\" | \"directory\"> {\n const stats = await stat(resolveLocalPath(inputPath));\n if (stats.isDirectory()) {\n return \"directory\";\n }\n if (stats.isFile()) {\n return \"file\";\n }\n throw new ValidationError(`Local path must be a file or directory: ${inputPath}`, {\n context: { path: inputPath }\n });\n}\n\nexport async function getLocalFileSize(inputPath: string): Promise<number> {\n const stats = await stat(resolveLocalPath(inputPath));\n return stats.size;\n}\n","import { readdir, stat } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport type { RemoteFileInfo, SftpTransport } from \"./transport.js\";\nimport { resolveLocalPath } from \"../paths/local-path.js\";\nimport { remoteJoin } from \"../paths/remote-path.js\";\n\nexport interface LocalFileEntry {\n absolutePath: string;\n relativePath: string;\n size: number;\n}\n\nexport async function walkLocalFiles(rootPath: string): Promise<LocalFileEntry[]> {\n const resolvedRoot = resolveLocalPath(rootPath);\n const stats = await stat(resolvedRoot);\n\n if (stats.isFile()) {\n return [\n {\n absolutePath: resolvedRoot,\n relativePath: path.basename(resolvedRoot),\n size: stats.size\n }\n ];\n }\n\n const files: LocalFileEntry[] = [];\n\n async function visit(directory: string): Promise<void> {\n const entries = await readdir(directory, { withFileTypes: true });\n for (const entry of entries) {\n const absolutePath = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n await visit(absolutePath);\n } else if (entry.isFile()) {\n const entryStats = await stat(absolutePath);\n files.push({\n absolutePath,\n relativePath: path.relative(resolvedRoot, absolutePath),\n size: entryStats.size\n });\n }\n }\n }\n\n await visit(resolvedRoot);\n return files;\n}\n\nexport interface RemoteFileEntry {\n remotePath: string;\n relativePath: string;\n size: number;\n}\n\nexport async function walkRemoteFiles(\n transport: SftpTransport,\n rootPath: string\n): Promise<RemoteFileEntry[]> {\n const rootEntries = await transport.list(rootPath);\n const files: RemoteFileEntry[] = [];\n\n async function visit(directory: string, relativeBase: string, entries: RemoteFileInfo[]): Promise<void> {\n for (const entry of entries) {\n const fullPath = remoteJoin(directory, entry.name);\n const relativePath = relativeBase ? remoteJoin(relativeBase, entry.name) : entry.name;\n if (entry.type === \"d\") {\n await visit(fullPath, relativePath, await transport.list(fullPath));\n } else if (entry.type === \"-\") {\n files.push({\n remotePath: fullPath,\n relativePath,\n size: entry.size\n });\n }\n }\n }\n\n await visit(rootPath, \"\", rootEntries);\n return files;\n}\n","import path from \"node:path\";\n\nimport { ValidationError } from \"../errors/index.js\";\n\nexport function assertRemotePath(inputPath: string, label = \"remote path\"): void {\n if (!inputPath || inputPath.trim().length === 0) {\n throw new ValidationError(`Invalid ${label}: remote paths must not be empty.`, {\n context: { path: inputPath }\n });\n }\n}\n\nexport function normalizeRemotePath(inputPath: string): string {\n assertRemotePath(inputPath);\n return path.posix.normalize(inputPath.replace(/\\\\/g, \"/\"));\n}\n\nexport function remoteJoin(...parts: string[]): string {\n const joined = path.posix.join(...parts);\n assertRemotePath(joined);\n return joined;\n}\n\nexport function remoteDirname(inputPath: string): string {\n assertRemotePath(inputPath);\n return path.posix.dirname(inputPath);\n}\n","import { access } from \"node:fs/promises\";\n\nimport { ValidationError } from \"../errors/index.js\";\nimport { assertDownloadDestination, assertLocalPathExists, resolveLocalPath } from \"../paths/local-path.js\";\nimport { assertRemotePath } from \"../paths/remote-path.js\";\nimport type { DownloadOptions, ScpServerOptions, UploadOptions } from \"../types/index.js\";\n\nfunction validatePort(port: number | undefined): void {\n if (port === undefined) {\n return;\n }\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new ValidationError(\"Port must be an integer between 1 and 65535.\", {\n context: { port }\n });\n }\n}\n\nfunction validateTimeout(timeout: number | undefined): void {\n if (timeout === undefined) {\n return;\n }\n if (!Number.isFinite(timeout) || timeout <= 0) {\n throw new ValidationError(\"Timeout must be a positive number.\", {\n context: { timeout }\n });\n }\n}\n\nexport async function validateServerOptions(options: ScpServerOptions): Promise<void> {\n if (!options.host) {\n throw new ValidationError(\"Host is required.\");\n }\n if (!options.username) {\n throw new ValidationError(\"Username is required.\");\n }\n\n validatePort(options.port);\n validateTimeout(options.timeout);\n\n if (options.privateKeyFile) {\n try {\n await access(resolveLocalPath(options.privateKeyFile));\n } catch (error) {\n throw new ValidationError(`Private key file does not exist: ${options.privateKeyFile}`, {\n cause: error,\n context: { privateKeyFile: options.privateKeyFile }\n });\n }\n }\n\n const hasAuthentication =\n Boolean(options.password) ||\n Boolean(options.privateKey) ||\n Boolean(options.privateKeyFile) ||\n Boolean(options.agent) ||\n Boolean(process.env.SSH_AUTH_SOCK);\n\n if (!hasAuthentication) {\n throw new ValidationError(\n \"Authentication is required. Provide a password, private key, private key file, or SSH agent.\"\n );\n }\n}\n\nexport async function validateUploadOptions(options: UploadOptions): Promise<void> {\n if (!options.localPath) {\n throw new ValidationError(\"Missing localPath.\");\n }\n if (!options.remotePath) {\n throw new ValidationError(\"Missing remotePath.\");\n }\n assertRemotePath(options.remotePath, \"remotePath\");\n validateTimeout(options.timeout);\n await assertLocalPathExists(options.localPath);\n\n if (!options.dryRun) {\n await validateServerOptions(options);\n }\n}\n\nexport async function validateDownloadOptions(options: DownloadOptions): Promise<void> {\n if (!options.remotePath) {\n throw new ValidationError(\"Missing remotePath.\");\n }\n if (!options.localPath) {\n throw new ValidationError(\"Missing localPath.\");\n }\n assertRemotePath(options.remotePath, \"remotePath\");\n validateTimeout(options.timeout);\n await assertDownloadDestination(options.localPath, options.createDirectories);\n\n if (!options.dryRun) {\n await validateServerOptions(options);\n }\n}\n","import { ScpNextClientImpl } from \"./client.js\";\nimport type { UploadOptions } from \"../types/index.js\";\n\nexport async function upload(options: UploadOptions): Promise<void> {\n const client = new ScpNextClientImpl(options);\n try {\n await client.upload(options.localPath, options.remotePath, options);\n } finally {\n await client.close();\n }\n}\n","import { ScpNextClientImpl } from \"./client.js\";\nimport type { DownloadOptions } from \"../types/index.js\";\n\nexport async function download(options: DownloadOptions): Promise<void> {\n const client = new ScpNextClientImpl(options);\n try {\n await client.download(options.remotePath, options.localPath, options);\n } finally {\n await client.close();\n }\n}\n","import { download } from \"./download.js\";\nimport { upload } from \"./upload.js\";\nimport { ValidationError } from \"../errors/index.js\";\nimport type { CopyOptions } from \"../types/index.js\";\n\nexport async function copy(options: CopyOptions): Promise<void> {\n if (options.source.type === \"local\" && options.destination.type === \"remote\") {\n await upload({\n ...options,\n localPath: options.source.path,\n remotePath: options.destination.path\n });\n return;\n }\n\n if (options.source.type === \"remote\" && options.destination.type === \"local\") {\n await download({\n ...options,\n remotePath: options.source.path,\n localPath: options.destination.path\n });\n return;\n }\n\n throw new ValidationError(\"copy() supports only local-to-remote or remote-to-local transfers.\", {\n context: {\n sourceType: options.source.type,\n destinationType: options.destination.type\n }\n });\n}\n"],"mappings":";AAAA,SAAS,UAAAA,SAAQ,SAAAC,cAAa;AAC9B,OAAOC,WAAU;;;ACDjB,SAAS,YAAAC,iBAAgB;AAEzB,OAAO,gBAAgB;;;ACFvB,IAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,sBACJ;AAEF,SAAS,eAAe,KAAsB;AAC5C,QAAM,aAAa,IAAI,QAAQ,WAAW,EAAE,EAAE,YAAY;A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,UAAM,OAAO,OAAO,QAAQ,WAAW,QAAQ,YAAY,OAAO;AAAA,EACpE,UAAE;AACA,UAAM,OAAO,MAAM;AAAA,EACrB;AACF;;;ACPA,eAAsB,SAAS,SAAyC;AACtE,QAAM,SAAS,IAAI,kBAAkB,OAAO;AAC5C,MAAI;AACF,UAAM,OAAO,SAAS,QAAQ,YAAY,QAAQ,WAAW,OAAO;AAAA,EACtE,UAAE;AACA,UAAM,OAAO,MAAM;AAAA,EACrB;AACF;;;ACLA,eAAsB,KAAK,SAAqC;AAC9D,MAAI,QAAQ,OAAO,SAAS,WAAW,QAAQ,YAAY,SAAS,UAAU;AAC5E,UAAM,OAAO;AAAA,MACX,GAAG;AAAA,MACH,WAAW,QAAQ,OAAO;AAAA,MAC1B,YAAY,QAAQ,YAAY;AAAA,IAClC,CAAC;AACD;AAAA,EACF;AAEA,MAAI,QAAQ,OAAO,SAAS,YAAY,QAAQ,YAAY,SAAS,SAAS;AAC5E,UAAM,SAAS;AAAA,MACb,GAAG;AAAA,MACH,YAAY,QAAQ,OAAO;AAAA,MAC3B,WAAW,QAAQ,YAAY;AAAA,IACjC,CAAC;AACD;AAAA,EACF;AAEA,QAAM,IAAI,gBAAgB,sEAAsE;AAAA,IAC9F,SAAS;AAAA,MACP,YAAY,QAAQ,OAAO;AAAA,MAC3B,iBAAiB,QAAQ,YAAY;AAAA,IACvC;AAAA,EACF,CAAC;AACH;","names":["access","mkdir","path","readFile","access","access","readFile","stat","path","path","path","stat","path","access","access","totalBytes","path","mkdir","access"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
`scp-next` separates the CLI from reusable transfer logic:
|
|
4
|
+
|
|
5
|
+
- `src/cli` parses operands and options, prints readable output, and sets exit codes.
|
|
6
|
+
- `src/config` loads JSON configuration, environment variables, profiles, jobs, and applies
|
|
7
|
+
precedence in `resolve-config.ts`.
|
|
8
|
+
- `src/client` owns the public client API and delegates remote operations to a transport
|
|
9
|
+
abstraction.
|
|
10
|
+
- `src/security` redacts secrets and configures host-key verification.
|
|
11
|
+
- `src/paths` keeps local OS path behavior separate from remote POSIX path behavior.
|
|
12
|
+
- `src/errors` defines stable typed errors.
|
|
13
|
+
|
|
14
|
+
## Dependency Choices
|
|
15
|
+
|
|
16
|
+
- `ssh2-sftp-client`: maintained SFTP client built on `ssh2`, avoiding manual protocol
|
|
17
|
+
implementation and remote shell commands for normal transfers.
|
|
18
|
+
- `commander`: small CLI parser with solid help/version support.
|
|
19
|
+
- `zod`: validates configuration file shape without exposing schema objects in the public API.
|
|
20
|
+
- `tsup`: emits ESM, CommonJS, declarations, and source maps with minimal packaging overhead.
|
|
21
|
+
- `vitest`: fast TypeScript-friendly unit and integration tests.
|
|
22
|
+
|
|
23
|
+
## Transfer Terminology
|
|
24
|
+
|
|
25
|
+
CLI commands always use `<source> <destination>`.
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
Operation Source Destination
|
|
29
|
+
Upload Local Remote
|
|
30
|
+
Download Remote Local
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The programmatic API uses `localPath` and `remotePath` for upload and download so callers do
|
|
34
|
+
not need to infer locality from transfer direction. Configured jobs use `source` and
|
|
35
|
+
`destination` because they describe a reusable transfer plan.
|
|
36
|
+
|
|
37
|
+
## SFTP Mechanism and Limitations
|
|
38
|
+
|
|
39
|
+
Transfers are implemented with SFTP. This improves compatibility with directory traversal,
|
|
40
|
+
progress callbacks, and avoiding shell command injection risk. Limitations inherited from the
|
|
41
|
+
selected dependency and SFTP servers include:
|
|
42
|
+
|
|
43
|
+
- Progress is based on file transfer callbacks and may not include server-side metadata time.
|
|
44
|
+
- Server support for symlinks, permissions, and special files varies; this initial version
|
|
45
|
+
transfers regular files and directories.
|
|
46
|
+
- Known-host parsing supports exact plain host entries, not hashed OpenSSH hostnames. Use
|
|
47
|
+
`hostFingerprint` when hashed known-hosts entries are required.
|
|
48
|
+
- Atomic replacement behavior depends on the server; overwrite control is checked before
|
|
49
|
+
transfer and is not a distributed lock.
|
|
50
|
+
|
|
51
|
+
## Integration Test Strategy
|
|
52
|
+
|
|
53
|
+
The committed integration tests use a mockable transport abstraction so no production SSH
|
|
54
|
+
server is required. A future CI job can add a local OpenSSH/SFTP container to verify live
|
|
55
|
+
authentication and host-key behavior against a disposable server.
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "scp-next",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A SCP CLI and library for secure SSH file transfers using SFTP.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"scp-next": "./dist/cli/index.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"CHANGELOG.md",
|
|
25
|
+
"docs"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup",
|
|
29
|
+
"clean": "rimraf dist coverage",
|
|
30
|
+
"dev": "tsx src/cli/index.ts",
|
|
31
|
+
"lint": "eslint .",
|
|
32
|
+
"format": "prettier --write .",
|
|
33
|
+
"format:check": "prettier --check .",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:coverage": "vitest run --coverage",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"prepublishOnly": "npm run clean && npm run typecheck && npm run lint && npm test && npm run build"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"scp",
|
|
41
|
+
"sftp",
|
|
42
|
+
"ssh",
|
|
43
|
+
"transfer",
|
|
44
|
+
"cli",
|
|
45
|
+
"typescript"
|
|
46
|
+
],
|
|
47
|
+
"author": {
|
|
48
|
+
"name": "Cheng",
|
|
49
|
+
"email": "mazeyqian@gmail.com",
|
|
50
|
+
"url": "https://github.com/chengchuu"
|
|
51
|
+
},
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/chengchuu/scp-next.git"
|
|
56
|
+
},
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/chengchuu/scp-next/issues"
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://github.com/chengchuu/scp-next#readme",
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=18.18.0"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"commander": "^12.1.0",
|
|
66
|
+
"ssh2-sftp-client": "^11.0.0",
|
|
67
|
+
"zod": "^3.23.8"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@eslint/js": "^9.17.0",
|
|
71
|
+
"@types/node": "^22.10.2",
|
|
72
|
+
"@types/ssh2-sftp-client": "^9.0.4",
|
|
73
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
74
|
+
"eslint": "^9.17.0",
|
|
75
|
+
"prettier": "^3.4.2",
|
|
76
|
+
"rimraf": "^6.0.1",
|
|
77
|
+
"tsup": "^8.3.5",
|
|
78
|
+
"tsx": "^4.19.2",
|
|
79
|
+
"typescript": "^5.7.2",
|
|
80
|
+
"typescript-eslint": "^8.18.1",
|
|
81
|
+
"vitest": "^4.1.9"
|
|
82
|
+
},
|
|
83
|
+
"overrides": {
|
|
84
|
+
"esbuild": "^0.28.1"
|
|
85
|
+
}
|
|
86
|
+
}
|