0

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 = "username@domain.com"
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
Gary
  • 31
  • 1
  • 6
  • Please provide a working example. We cannot see, what your variables actually contain. You can, of course, obfuscate username and password or leave them out entirely, but you are asking about the host, so what is in the `ip_address` and `host_name` variables? – Cow May 12 '23 at 06:45
  • Added the variables – Gary May 12 '23 at 06:48
  • pysmb includes a `NetBIOS.queryIPForName` method that can find the machine name for a given IP address. – Tim Roberts Jun 20 '23 at 17:32

1 Answers1

0

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)
Faaceb
  • 3
  • 3