How to read and write files on a network drive with an SMB Connector
- March 24, 2023
In this article, we’ll see how to read files from a network drive and write a file to a network drive.
What is SMB?
The Server Message Block (SMB) protocol is a network file sharing protocol to access remote files. It lets you share files, printers, serial ports and other resources on shared/network drive. Using this protocol, you can communicate with any server configured to receive an SMB client request.
By default, the SMB protocol is disabled on Windows. (Learn how to enable SMB protocol on Windows.)
Prerequisites:
- Anypoint Platform account
- Anypoint Studio 7.6 or later
- SMB share and its authentication credentials — for this integration, we created SMB as a shared drive
SMB share snapshot
Let’s start with integration
To read and write files from/to SMB share follow these steps:
- Download SMB Connector from Exchange (Version = 3.0.1)
- Add SMB Connector Config in Global Elements and configure the following parameters:
Domain: Enter the Windows domain for the user to log in with
Host: Hostname of server hosting a shared drive
Share: The named path of shared drive
Username: Enter the username to login
Password: Enter the corresponding password
File age: Minimum age of file to perform the operationSMB Connector configuration - Perform a Test Connection to make sure the connection details are correct
Test connection result
- Read a file from a shared drive using the SMB File Read operation — refer to the following File Read configuration
SMB File Read operation configuration
- Test the SMB file read flow using Postman; the output MIME Type is “application/octet-stream”
SMB file.csv file contentFile Read operation Postman snapshot
- Write a file to the network drive using the SMB File Write operation — refer to the following File Read configuration
SMB File Write operation configuration
- Test the SMB file write flow using Postman
File Write operation Postman snapshotSMB share snapshot after writing release.txt file
Reference:
https://www.mulesoft.com/exchange/com.mulesoft.connectors/mule-smb-connector/
— By Saddam Shaikh