Article
· Sep 13, 2022 3m read

Create, List, Upload and Download network files and folders Using SMB Protocol and IRIS Interoperability

Samba is the standard for file services interoperability across Linux, Unix, DOS, Windows, OS/2 and other OS. Since 1992, Samba has provided secure, stable and fast file services for all clients (OS and programs) using the SMB/CIFS protocol. Network administrators have used SAMBA to create shared network folders to allow company employees to create, edit and view corporate files as if they were on their computers locally, when these files are physically located on a network file server. It is possible to create a network folder in Linux and see it as a shared folder in Windows, for example. 

Currently IRIS connectors do not support accessing and writing to remote files and folders using SMB protocol. So it is necessary to use FTP. But, now we have Python, which has the smbprotocol library (https://pypi.org/project/smbprotocol). Based on this library, an interoperability application (production) was created for listing, recording and deleting files and folders using the SMB protocol. Now, your IRIS applications can write or access network files easily. The application is called samba-iris-adapter (https://openexchange.intersystems.com/package/samba-iris-adapter).

 

Application installation

Installation: ZPM

1. Open IRIS Namespace with Interoperability Enabled. Open Terminal and call:

USER>zpm "install samba-iris-adapter"

Installation: Docker

1. Clone/git pull the repo into any local directory

$ git clone https://github.com/yurimarx/samba-iris-adapter.git

2. Open the terminal in this directory and run:

$ docker-compose build

3. Run the IRIS container with your project:

$ docker-compose up -d

How to Run the App

1. Go to the Interoperability > Configure > Credentials:

2. Set credentials and save with these values:

ID: SambaCredentials
User name: bob
Password: bobspasswd 
Credentials

3. Open the production http://localhost:52795/csp/user/EnsPortal.ProductionConfig.zen?PRODUCTION=dc.samba.SambaProduction and start it.

4. Go to your REST client app and use these REST operations (with basic auth and credentials _SYSTEM/SYS):

5. Create a new Remote Folder: POST http://localhost:52795/csp/samba/CreateFolder with JSON Body: {"Folder":"samplefolder"}

6. To Send a File to a Remote Folder: POST http://localhost:52795/csp/samba/CreateFile/samplefolder with form-data selected to send multipart file. The name of the multipart file is file and in value select any file from your computer, check this image with a example using postman:

7. List files inside a Remote Folder: GET http://localhost:52795/csp/samba/ListFilesIntoFolder/samplefolder:


8. Download the File: POST http://localhost:52795/csp/samba/DownloadFile with JSON Body: {"Folder":"samplefolder", "Filename":"cat.jpg"}:

9. See productions messages into http://localhost:52795/csp/user/EnsPortal.ProductionConfig.zen?$NAMESPACE=USER&$NAMESPACE=USER& > Messages tab > click the Session:

10. Check the new folder and file inside /mnt2 folder inside samba docker instance:

Enjoy!

Discussion (4)4
Log in or sign up to continue

Hi Yuri,

Your video is now on InterSystems Developers YouTube:

⏯ List, Download and Upload Files using InterSystems IRIS and Samba Protocol SMB

https://www.youtube.com/embed/INpz_Q3rgn8
[This is an embedded link, but you cannot view embedded content directly on the site because you have declined the cookies necessary to access it. To view embedded content, you would need to accept all cookies in your Cookies Settings]

Thank you!

Nice work!  The Docker version ran perfect. I then tried to install and run it on my local IRIS instance with ZPM and I get the execution error: 

ERROR <Ens>ErrException: <THROW>CreateFolder+9^dc.samba.SambaBusinessOperation.1 *%Exception.PythonException <PYTHON EXCEPTION> 246 <class 'ModuleNotFoundError'>: No module named 'smbclient' -- logged as '-' number - @'    Set sc = ##class(dc.samba.SambaService).CreateFolder(server, port, share, username, password, folder)'

I had run irispip to load smbprotocol, which seemed to run fine:

..\bin\irispip install --target \InterSystems\IRISHealth\python smbprotocol

but the smbclient module still seems to be missing.

What am I missing?

Thanks!!