Establish the SMB connection to the remote SMB/CIFS server. You must call this method before attempting any of the file operations with the remote server. This method will block until the SMB connection has attempted at least one authentication. :param port: Defaul
(self, ip, port = 139, sock_family = None, timeout = 60)
| 98 | # |
| 99 | |
| 100 | def connect(self, ip, port = 139, sock_family = None, timeout = 60): |
| 101 | """ |
| 102 | Establish the SMB connection to the remote SMB/CIFS server. |
| 103 | |
| 104 | You must call this method before attempting any of the file operations with the remote server. |
| 105 | This method will block until the SMB connection has attempted at least one authentication. |
| 106 | |
| 107 | :param port: Defaults to 139. If you are using direct TCP mode (is_direct_tcp=true when creating this SMBConnection instance), use 445. |
| 108 | :param sock_family: In Python 3.x, use *None* as we can infer the socket family from the provided *ip*. In Python 2.x, it must be either *socket.AF_INET* or *socket.AF_INET6*. |
| 109 | :return: A boolean value indicating the result of the authentication atttempt: True if authentication is successful; False, if otherwise. |
| 110 | """ |
| 111 | if self.sock: |
| 112 | self.sock.close() |
| 113 | |
| 114 | self.auth_result = None |
| 115 | if sock_family: |
| 116 | self.sock = socket.socket(sock_family) |
| 117 | self.sock.settimeout(timeout) |
| 118 | self.sock.connect(( ip, port )) |
| 119 | else: |
| 120 | self.sock = socket.create_connection(( ip, port ), timeout = timeout) |
| 121 | |
| 122 | self.is_busy = True |
| 123 | try: |
| 124 | if not self.is_direct_tcp: |
| 125 | self.requestNMBSession() |
| 126 | else: |
| 127 | self.onNMBSessionOK() |
| 128 | while self.auth_result is None: |
| 129 | self._pollForNetBIOSPacket(timeout) |
| 130 | finally: |
| 131 | self.is_busy = False |
| 132 | |
| 133 | return self.auth_result |
| 134 | |
| 135 | def close(self): |
| 136 | """ |
no test coverage detected