forked from opinkerfi/pysmbclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
105 lines (76 loc) · 2.64 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
== Python smbclient wrapper. ==
This is a wrapper that works by running the "smbclient" subprocess and providing
an API similar to the one provided by python `os` module.
It is an ugly hack, but it is here for anyone that finds it useful.
The programmer before me was using a "bash" file with lots of smbclient calls,
so I think my solution is at least better.
=== Usage example ===
{{{
>>> smb = smbclient.SambaClient(server="MYSERVER", share="MYSHARE",
username='foo', password='bar', domain='baz')
>>> print smb.listdir("/")
[u'file1.txt', u'file2.txt']
>>> f = smb.open('/file1.txt')
>>> data = f.read()
>>> f.close()
>>> smb.rename(u'/file1.txt', u'/file1.old')
}}}
=== Documentation ===
==== Creating the object ====
{{{
import smbclient
smb = smbclient.SambaClient(server, share, username=None, password=None,
domain=None, resolve_order=None, port=None, ip=None,
terminal_code=None, buffer_size=None,
debug_level=None, config_file=None, logdir=None,
netbios_name=None, kerberos=False)
}}}
If you want to use kerberos authentication just use the argument
{{{kerberos=True}}} and you don't need to pass username and password.
==== Supported methods of operation ====
{{{
chmod(path, *modes)
Set/reset file modes
Tested with: AHS
smbc.chmod('/file.txt', '+H')
close()
Closes the connection, flushes and closes all open remote files.
diskinfo(self)
Fetches information about a volume
info(path)
Fetches information about a file
exists(path)
Returns True if path exists in the remote host
isdir(path)
Returns True if path is a directory/folder
isfile(path)
Returns True if path is a regular file
glob(path)
Lists a glob (example: "/files/somefile.*")
returns a list of tuples in the format:
[(filename, modes, size, date), ...]
lsdir(path)
Lists a directory
returns a list of tuples in the format:
[(filename, modes, size, date), ...]
listdir(path)
Emulates os.listdir()
mkdir(path)
Creates a new folder remotely
rmdir(path)
Removes a remote empty folder
open(path, mode='r')
Opens the file indicated by path and returns it as a file-like object
rename(old_name, new_name)
volume()
Fetches the volume name
serial()
Fetches the volume serial
unlink(path) or remove(path)
Removes/deletes/unlinks a file
download(remote_path, local_path)
upload(local_path, remote_path)
upload_update(local_path, remote_path)
netsend(destination, message)
Sends a message, using netsend
}}}