copyData

abstract suspend fun copyData(srcHandle: SftpFileHandle, srcOffset: Long, length: Long, dstHandle: SftpFileHandle, dstOffset: Long, timeoutMs: Long = 0): SftpResult<Unit>(source)

Copies length bytes from srcHandle at srcOffset into dstHandle at dstOffset, entirely on the server — no data crosses the wire. This is the "copy-data" SFTP protocol extension OpenSSH added in 9.0 (April 2022); it lets the server use an efficient server-side copy (e.g. copy_file_range() on Linux) instead of the client reading the whole file and writing it back, and works even for accounts restricted to internal-sftp with no shell access (where server-side cp via SSH exec cannot run at all).

Both handles must already be open (open with SftpOpenFlag.READ for srcHandle, SftpOpenFlag.WRITE for dstHandle) — this call does not open, create, or close anything. Only regular files are supported; there is no protocol-level operation for copying whole directory trees, so recursive copies still need to be driven by the caller (walk the tree, mkdir each directory, copyData each regular file).

Check extensions for "copy-data" before calling, or be prepared to fall back on an SftpResult.ServerError with SftpStatusCode.OP_UNSUPPORTED — older or non-OpenSSH servers may not implement this extension at all.

Parameters

length

Number of bytes to copy; 0 means "copy through EOF of the source file".

timeoutMs

Maximum time to wait for the server response; 0 (default) waits until completion or disconnect. The caller may also cancel the coroutine. A timeout or cancellation stops waiting but does not cancel the copy on the server.