SMB in Python
Read and write files on SMB and Windows shares from Python services.
Your services reach Windows shares and other SMB servers through self.smb. Every remote path starts with the name of the share, e.g. Finance/invoices/2026-08.csv.
Upload and download
from zato.server.service import Service
class SyncInvoices(Service):
def handle(self):
conn = self.smb['My Share']
# Upload a local file to the share
conn.upload('/local/invoices/2026-08.csv', 'Finance/incoming/2026-08.csv')
# Download a file from the share
conn.download_file('Finance/reports/summary.csv', '/local/reports/summary.csv')
Read and write remote files directly
The data is text, bytes, a dict, a list or the service's own input, and the last three are written out as JSON:
from zato.server.service import Service
class ExportOrder(Service):
def handle(self):
conn = self.smb['My Share']
data = self.request.input
conn.write(data, 'Finance/orders/order-4711.json')
ack = conn.read('Finance/acks/order-4711.txt')
self.response.payload = {'ack': ack}
Guaranteed delivery
.publish spools the data locally and retries until the share accepts it:
from zato.server.service import Service
class PublishReport(Service):
def handle(self):
conn = self.smb['My Share']
conn.publish(self.request.input, 'Finance/reports/daily.csv')
List and manage directories
Missing parent directories are created along with the one you ask for:
from zato.server.service import Service
class ArchiveInvoices(Service):
def handle(self):
conn = self.smb['My Share']
conn.create_directory('Finance/archive/2026/08')
for item in conn.list('Finance/incoming'):
self.logger.info('%s %s', item.name, item.size_human)
conn.move('Finance/incoming/' + item.name, 'Finance/archive/2026/08/' + item.name)
Configuration
The enmasse YAML for the connection:
smb:
- name: My Share
host: files.example.com
port: 445
username: zato
password: Zato_Enmasse_Env.My_Share_Password
See also
| Feature | What it does |
|---|---|
| Connection API | Every method of SFTP and SMB connection objects |
| File transfer schedules | Have Zato watch a directory on the share and invoke a service per file |
| SFTP | The same API against SFTP servers |
| SharePoint and OneDrive | SharePoint and OneDrive files through the Graph API |