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 Connector1
    SMB share snapshot

Let’s start with integration

To read and write files from/to SMB share follow these steps:

  1. Download SMB Connector from Exchange (Version = 3.0.1)
  2. 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 operation

    SMB Connector2
    SMB Connector configuration
  3. Perform a Test Connection to make sure the connection details are correct
    SMB Connector3
    Test connection result
  4. Read a file from a shared drive using the SMB File Read operation — refer to the following File Read configuration
    SMB Connector4
    SMB File Read operation configuration
  5. Test the SMB file read flow using Postman; the output MIME Type is “application/octet-stream”
    SMB Connector5
    SMB file.csv file content
    SMB Connector6
    File Read operation Postman snapshot
  6. Write a file to the network drive using the SMB File Write operation — refer to the following File Read configuration
    SMB Connector7
    SMB File Write operation configuration
  7. Test the SMB file write flow using Postman
    SMB Connector8
    File Write operation Postman snapshot
    SMB Connector9
    SMB share snapshot after writing release.txt file

Reference:

https://www.mulesoft.com/exchange/com.mulesoft.connectors/mule-smb-connector/

— By Saddam Shaikh