Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #37: Document how to get a shared printer listing #38

Merged
merged 2 commits into from
Oct 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,55 @@ NOTE: to run your tests, you need
* rw permissions
* guest ok = no

Examples
------

Directory listing

~~~
>>> import smbc
>>> ctx = smbc.Context (auth_fn=my_auth_callback_fn)
>>> entries = ctx.opendir ("smb://SERVER").getdents ()
>>> for entry in entries:
... print entry
<smbc.Dirent object "music" (File share) at 0x7fbd7c42b3a0>
<smbc.Dirent object "IPC$" (IPC share) at 0x7fbd7c42b148>
<smbc.Dirent object "Charlie" (Printer share) at 0x7fbd7c42b3c8>
>>> d = ctx.open ("smb://SERVER/music")
~~~

Shared Printer Listing

~~~
>>> import smbc
>>> ctx = smbc.Context()
>>> ctx.optionNoAutoAnonymousLogin = True
>>> ctx.functionAuthData = lambda se, sh, w, u, p: (domain_name, domain_username, domain_password)
>>> uri = 'smb://' + smb_server
>>> shared_printers = []
>>> entries = ctx.opendir(uri).getdents()
>>> for entry in entries:
>>> if entry.smbc_type == 4:
>>> shared_printers.append(entry.name)
~~~

Write file

~~~
>>> import smbc
>>> import os
>>> ctx = smbc.Context (auth_fn=my_auth_callback_fn)
>>> file = ctx.open ("smb://SERVER/music/file.txt", os.O_CREAT | os.O_WRONLY)
>>> file.write ("hello")
~~~

Read file

~~~
>>> import smbc
>>> ctx = smbc.Context (auth_fn=my_auth_callback_fn)
>>> file = ctx.open ("smb://SERVER/music/file.txt")
>>> print file.read()
hello
~~~