What can cause pysmb to crash when OSX Finder "Connecting to Server ..." succeeds?
(originally asked by StackOverflow, but I think there are more suitable experts here):
I am trying to transfer a file from a remote samba share (on a windows server) to a python script (works on OSX 10.10). I can install the share using Finder Go dialog -> "Connect to Server ...", but when I try to use the same credentials with the pysmb module in python (v 2.7.6) I get "Connection Refused". ":
>>> from smb.SMBConnection import SMBConnection
>>> conn =SMBConnection('myuser', 'mypassword','me','remote-server-netbios-name')
>>> assert conn.connect('remoteserver.mycompany.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/smb/SMBConnection.py", line 103, in connect
self.sock.connect(( ip, port ))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 61] Connection refused
Likewise, if I try to use the NetBIOS package to get the name of the remote server (to make sure I understand correctly), it just shuts down:
>>> from nmb.NetBIOS import NetBIOS
>>>
>>> def getBIOSName(remote_smb_ip, timeout=30):
... try:
... bios = NetBIOS()
... srv_name = bios.queryIPForName(remote_smb_ip, timeout=timeout)
... except:
... print >> sys.stderr, "Looking up timeout, check remote_smb_ip again!!"
... finally:
... bios.close()
... return srv_name
...
>>> getBIOSName('remoteserver.mycompany.com')
The same code works great to get files from samba share on my ubuntu server at home. I suspect there might be some permissions or firewall issues on the server itself. Any ideas on what ports / permissions need to be opened to make this work?
EDIT: With the suggestion from the board below, I tried the connect function by specifying port 445. However, this generates a "Connection reset by peer" error:
>>> assert conn.connect('remoteserver.mycompany.com', 445)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/smb/SMBConnection.py", line 112, in connect
self._pollForNetBIOSPacket(timeout)
File "/Library/Python/2.7/site-packages/smb/SMBConnection.py", line 511, in _pollForNetBIOSPacket
d = self.sock.recv(read_len)
socket.error: [Errno 54] Connection reset by peer
source to share
This worked for me: 1.username has no domain part 2.is_direct_tcp = True 3.connecting to port 445
conn = SMBConnection('user', 'password', socket.gethostname(), 'remote_server_name', 'domain_name', is_direct_tcp=True)
assert conn.connect('server_ip', 445)
SMB.SMBConnection INFO Authentication (on SMB2) successful!
source to share