def connect(self): while not self.is_connected: self.smb_conn = self.__connect() if not self.smb_conn: interval = random.randint(0, ss.get("reconnect_interval", MAX_INTERVAL)) logger.info("connection will be established in %ss" % interval) time.sleep(interval) return self.smb_conn
def __connect(self): conn_cnt = 0 logger.info("trying to connect smb server on %s:%s" % (self.ip, self.port)) while conn_cnt < ss.get("reconnect_times", 3): try: smb_conn = SMBConnection( self.username, self.password, self.client_name, self.server_name, use_ntlm_v2=self.use_ntlm_v2 ) smb_conn.connect(self.ip, self.port) logger.info("connected to smb server") return smb_conn except Exception, e: conn_cnt += 1 logger.info("connecting failed, times to reconnect: %d" % conn_cnt)