We establish the connection using smbprotocol
library in Python and Domain join to provide permission on fileshare.
from smb.SMBConnection import SMBConnection
from smb.smb2_constants import SMB2_DIALECT_2
server_name = 'fileshare_host_name'
domain = 'your_domain'
share_name = 'your_share_name' #(example: \\xyz02.abc.com\env\Test, share name here is Test)
username = 'your.username'
password = 'your_password'
# Create an SMBConnection object with SMBv2
conn = SMBConnection(username, password, 'client', server_name, domain, use_ntlm_v2=True, is_direct_tcp=True)
# Connect to the SMB share
conn.connect(server_name, 445)
# List files in the share
file_list = conn.listPath(share_name, '')
print(file_list)
# Iterate through the file list and print the filenames
for file in file_list:
if file.filename not in ('.', '..'):
print(file.filename)
conn.close()