SambaSession
objectOne Samba/SMB share. Paths are relative to the root of the share. Each operation opens and closes its own connection, so the session can be used for a long time without keeping a connection alive.
- Kind Object
- Library Samba
- Category Remote & Infrastructure
- Functions 5
How to get one
- Samba .newSession()
- SambaSession
local share = Samba.newSession(hostname, username, password, shareName)Returned by
Functions
-
listFilestable Lists the names of the entries in a directory of the share that match a search pattern. -
copyRemoteToLocalself Downloads a file from the share into the project. -
copyLocalToRemoteself Uploads a project file (fetched from the Reflex server first when it is not in the workspace) to the share. -
removeFileself Deletes a file in the share. -
closeself Releases the SMB client of this session.
listFiles()
Section titled “listFiles()”share.listFiles(path: string, searchPattern: string)→table Lists the names of the entries in a directory of the share that match a search pattern. Files and subdirectories are both returned, as names only. SMB servers usually include the special entries "." and "..". Use "" as path for the share root and "*" as pattern for everything.
Parameters
-
pathstring - Directory in the share; "" for the root
-
searchPatternstring - Wildcard pattern, for example "*.xlsx" or "*"
Returns
Example
for _, name in ipairs(share.listFiles("2025", "*.xlsx")) do print(name)endcopyRemoteToLocal()
Section titled “copyRemoteToLocal()”share.copyRemoteToLocal(remoteFile: string, localFile: string)→self Downloads a file from the share into the project. Missing local folders are created and an existing local file is overwritten. Raises "Failed to copy remote file to local file: ..." on failure.
Parameters
-
remoteFilestring - Path of the file in the share
-
localFilestring - Path in the project to save the file as
Returns
Example
share.copyRemoteToLocal("2025/summary.xlsx", "input/summary.xlsx")copyLocalToRemote()
Section titled “copyLocalToRemote()”share.copyLocalToRemote(localFile: string, remoteFile: string, overwrite?: boolean)→self Uploads a project file (fetched from the Reflex server first when it is not in the workspace) to the share. Missing folders on the share are created. When the remote file exists it is replaced only if overwrite is true; otherwise the copy fails.
Parameters
-
localFilestring - Path of the file in the project
-
remoteFilestring - Path in the share to write the file to
-
overwriteboolean optional - true to replace an existing remote file; default false
Returns
Example
share.copyLocalToRemote("output/report.pdf", "2025/05/report.pdf", true)removeFile()
Section titled “removeFile()”share.removeFile(remoteFile: string)→self Deletes a file in the share. Raises an error when it cannot be deleted.
Parameters
-
remoteFilestring - Path of the file in the share
Returns
close()
Section titled “close()”share.close()→self Releases the SMB client of this session. Operations already close their own connection, so this is only housekeeping; do not use the session afterwards.
Returns