I'm not sure if this helps in your case, but it works for me:
The 3rd parameter to the
SmbConnection
should be (I think) theclient_machine_name
, so I pass there what I get fromsocket.gethostname()
.I'm not using the
sign_options
andis_direct_tcp
I just leave the default values.
This works for me with both samba and windows shares (I just have to pass a different port number sometimes).
Here is the code I use:
class Smb(object):
def __init__(self, username, password, server, share, port=139):
# split username if it contains a domain (domain\username)
domain, username = username.split('\\') if username.count('\\') == 1 else ('', username)
# setup data
self.domain = str(domain)
self.username = str(username)
self.password = str(password)
self.client = socket.gethostname()
self.server = str(server)
self.server_ip = socket.gethostbyname(server)
self.share = str(share)
self.port = port
self.conn = None
self.connected = False
# SMB.SMBConnection logs too much
smb_logger = logging.getLogger('SMB.SMBConnection')
smb_logger.setLevel(logging.WARNING)
def connect(self):
try:
self.conn = SMBConnection(self.username, self.password,
self.client, self.server,
use_ntlm_v2=True, domain=self.domain)
self.connected = self.conn.connect(self.server_ip, self.port)
logger.info('Connected to %s' % self.server)
return self.connected
except Exception, e:
logger.error('Connect failed. Reason: %s', e)
return False
And use it as:
smb = Smb('domain\\user', 'password', 'server', 'share_name')