Reputation: 31
I need to connect to Windows shared drive in Python, and for that I'm using the pysmb
library.
The code I have used is as follows:
from smb.SMBConnection import SMBConnection
username = "[email protected]"
password = "password"
client_machine_name = "any_name"
hostname = "server_20xx"
ip_address = "10.10.xxx.xx"
# Create the connection object
conn = SMBConnection(username, password, client_machine_name,
host_name, use_ntlm_v2=True)
# Connect to the server
conn.connect(host_name, 139)
Since the UNC can be either \\ip_address\share_name
or \\hostname\share_name
, why doesn't the smb client accept ip_address for establishing a connection?
When I use
conn = SMBConnection(username, password, client_machine_name,
ip_address, use_ntlm_v2=True)
conn.connect(ip_address, 139)
The error returned is
raise NotConnectedError
smb.base.NotConnectedError
Upvotes: 0
Views: 892
Reputation: 3
Try to add the following parameter 'is_direct_tcp=True' on SMBConnection method and change connection port from 139 to 445:
conn = SMBConnection(username, password, client_machine_name,
ip_address, use_ntlm_v2=True, is_direct_tcp=True)
conn.connect(ip_address, 445)
Upvotes: 0