SmbShare

class SmbShare : AutoCloseable

Provides file and directory operations on a connected SMB shared folder (SMB2 TREE_CONNECT).

Properties

Link copied to clipboard
Link copied to clipboard
val encryptShare: Boolean
Link copied to clipboard
val isClosed: Boolean
Link copied to clipboard
val shareName: String
Link copied to clipboard
val treeId: UInt

Functions

Link copied to clipboard
suspend fun appendBytes(path: String, data: ByteArray)

Appends a ByteArray to the end of a file, creating the file if it does not exist.

Link copied to clipboard
open override fun close()
Link copied to clipboard
suspend fun closeSuspend()

Sends an SMB2 TREE_DISCONNECT request to disconnect from this shared folder.

Link copied to clipboard
suspend fun createDirectory(path: String)

Creates a new directory at path.

Link copied to clipboard
suspend fun deleteDirectory(path: String)

Deletes the empty directory at path.

Link copied to clipboard
suspend fun deleteFile(path: String)

Deletes the file at path.

Link copied to clipboard
suspend fun deleteRecursively(path: String)

Deletes the file or directory at path, recursively removing all descendants if it is a directory.

Link copied to clipboard
suspend fun exists(path: String): Boolean

Returns whether a file or directory exists at the specified path.

Link copied to clipboard
suspend fun listDirectory(path: String = "", pattern: String = "*", bufferSize: Int = client.config.queryDirectoryBufferSize): List<SmbDirectoryEntry>

Lists files and subdirectories within the specified directory.

Link copied to clipboard
suspend fun openFile(path: String, desiredAccess: UInt = SmbAccessMask.READ_DEFAULT, shareAccess: UInt = SmbShareAccess.ALL, createDisposition: SmbCreateDisposition = SmbCreateDisposition.FILE_OPEN, fileAttributes: UInt = SmbFileAttributes.NORMAL, createOptions: UInt = SmbCreateOptions.FILE_NON_DIRECTORY_FILE or SmbCreateOptions.FILE_SYNCHRONOUS_IO_NONALERT): SmbFile

Opens a file with the specified access mask and sharing mode, returning an SmbFile handle.

Link copied to clipboard
suspend fun openRandomAccessFile(path: String, mode: SmbRandomAccessMode, bufferSize: Int = client.config.randomAccessBufferSize): SmbRandomAccessFile

Opens and returns an SmbRandomAccessFile with the specified SmbRandomAccessMode.

suspend fun openRandomAccessFile(path: String, mode: String = "r", bufferSize: Int = client.config.randomAccessBufferSize): SmbRandomAccessFile

Opens and returns an SmbRandomAccessFile modeled after java.io.RandomAccessFile.

Link copied to clipboard
suspend fun openSink(path: String, append: Boolean = false, overwrite: Boolean = true): Sink

Opens and returns a buffered kotlinx.io.Sink for writing to the file at path. Closing the returned Sink flushes pending data and closes the underlying SmbFile handle.

Link copied to clipboard
suspend fun openSource(path: String): Source

Opens and returns a buffered kotlinx.io.Source for reading the file at path. Closing the returned Source also closes the underlying SmbFile handle.

Link copied to clipboard
suspend fun readBytes(path: String): ByteArray

Reads the entire contents of a file into a ByteArray.

Link copied to clipboard
suspend fun readText(path: String): String

Reads the entire contents of a file decoded as a UTF-8 String.

Link copied to clipboard
suspend fun rename(fromPath: String, toPath: String, replaceIfExists: Boolean = true)

Renames or moves a file or directory from fromPath to toPath (FileRenameInformation).

Link copied to clipboard
suspend fun stat(path: String): SmbFileMetadata

Retrieves metadata for the file or directory at the specified path.

Link copied to clipboard
suspend fun writeBytes(path: String, data: ByteArray, overwrite: Boolean = true)

Writes a ByteArray to a file.

Link copied to clipboard
suspend fun writeText(path: String, text: String, overwrite: Boolean = true)

Encodes text as UTF-8 and writes it to a file.