Connect to the FTP server.
540503
public function connect()
    {
        if ($this->ssl) {
            $this->connection = ftp_ssl_connect($this->getHost(), $this->getPort(), $this->getTimeout());
        } else {
            $this->connection = ftp_connect($this->getHost(), $this->getPort(), $this->getTimeout());
        }

        if ( ! $this->connection) {
            throw new RuntimeException('Could not connect to host: ' . $this->getHost() . ', port:' . $this->getPort());
        }

        $this->login();
        $this->setUtf8Mode();
        $this->setConnectionPassiveMode();
        $this->setConnectionRoot();
        $this->isPureFtpd = $this->isPureFtpdServer();
    }
697836
def _connect(self, servers):
        
        self._do_connect(servers.split(' '))
        self._verify_connection(verbose=True)
575528
private function connect()
    {
        if (!$this->stream) {
            $errorNum = 0;
            $errorMsg = "";
            $context = @stream_context_create($this->streamOptions);
            $this->stream = @stream_socket_client(
                sprintf('%1$s:%2$d', $this->host, $this->port),
                $errorNum,
                $errorMsg,
                $this->timeOut,
                STREAM_CLIENT_CONNECT,
                $context
            );

            if (!$this->stream) {
                throw SMTPException::connectionError($errorNum, $errorMsg);
            }

            $this->read(); // Read response from server
            if ($this->lastResponseCode() !== 220) {
                throw SMTPException::unexpectedResponse("CONNECT", 220, $this->lastResponseCode());
            }

            // Build specs/options available at remote SMTP server
            $this->smtpServerOptions(
                $this->command("EHLO", $this->serverName)
            );

            // Use TLS?
            if ($this->secure === true) {
                if ($this->options["startTLS"] !== true) {
                    throw SMTPException::tlsNotAvailable();
                }

                $this->command("STARTTLS", null, 220);
                $tls = @stream_socket_enable_crypto($this->stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
                if (!$tls) {
                    throw SMTPException::tlsNegotiateFailed();
                }

                $this->command("EHLO", $this->serverName); // Resend EHLO command
            }

            // Authenticate
            if ($this->options["authLogin"] === true) {
                try {
                    $this->command("AUTH LOGIN", null, 334);
                    $this->command(base64_encode($this->username ?? " "), null, 334);
                    $this->command(base64_encode($this->password ?? " "), null, 235);
                } catch (SMTPException $e) {
                    throw SMTPException::authFailed($this->lastResponse);
                }
            } elseif ($this->options["authPlain"] === true) {
                // Todo: plain authentication
                throw SMTPException::authUnavailable();
            } else {
                throw SMTPException::authUnavailable();
            }
        } else {
            try {
                if (!stream_get_meta_data($this->stream)["timed_out"]) {
                    throw new SMTPException(__METHOD__, "Timed out");
                }

                $this->command("NOOP", null, 250);
            } catch (SMTPException $e) {
                $this->stream = null;
                $this->connect();
                return;
            }
        }
    }
470031
def connect(self):
        """"""
        device = None
        # logger.debug("Connecting to: {}".format(str(self)))
        for device in self.devices:
            if not device.connected:
                self.connection.emit_message("Connecting {}".format(str(device)), log_level=logging.INFO)
                protocol_name = device.get_protocol_name()
                device.protocol = make_protocol(protocol_name, device)
                command = device.protocol.get_command()
                self.ctrl.spawn_session(command=command)
                try:
                    result = device.connect(self.ctrl)
                except CommandSyntaxError as exc:
                    # all commands during discovery provides itself in exception except
                    # spawn session which is handled differently. If command syntax error is detected during spawning
                    # a new session then the problem is either on jumphost or csm server.
                    # The problem with spawning session is detected in connect FSM for telnet and ssh.
                    if exc.command:
                        cmd = exc.command
                        host = device.hostname
                    else:
                        cmd = command
                        host = "Jumphost/CSM"

                    self.connection.log(
                        "Command not supported or not authorized on {}: '{}'".format(host, cmd))
                    raise CommandError(message="Command not supported or not authorized",
                                       command=cmd,
                                       host=host)

                if result:
                    # logger.info("Connected to {}".format(device))
                    self.connection.emit_message("Connected {}".format(device), log_level=logging.INFO)
                else:
                    if device.last_error_msg:
                        message = device.last_error_msg
                        device.last_error_msg = None
                    else:
                        message = "Connection error"

                    self.connection.log(message)
                    raise ConnectionError(message)  # , host=str(device))

        if device is None:
            raise ConnectionError("No devices")

        return True
1304088
def _connect(self):
        """"""
        while self.protocol:
            _LOGGER.info('Trying to connect to %s', self.server_address)
            try:
                sock = socket.create_connection(
                    self.server_address, self.reconnect_timeout)
            except socket.timeout:
                _LOGGER.error(
                    'Connecting to socket timed out for %s',
                    self.server_address)
                _LOGGER.info(
                    'Waiting %s secs before trying to connect again',
                    self.reconnect_timeout)
                time.sleep(self.reconnect_timeout)
            except OSError:
                _LOGGER.error(
                    'Failed to connect to socket at %s', self.server_address)
                _LOGGER.info(
                    'Waiting %s secs before trying to connect again',
                    self.reconnect_timeout)
                time.sleep(self.reconnect_timeout)
            else:
                self.tcp_check_timer = time.time()
                self.tcp_disconnect_timer = time.time()
                transport = TCPTransport(
                    sock, lambda: self.protocol, self._check_connection)
                poll_thread = threading.Thread(target=self._poll_queue)
                self._stop_event.clear()
                poll_thread.start()
                transport.start()
                transport.connect()
                return
281276
protected function connect()
    {
        $this->client = new Client(array(
            'host'   => $this->instance->getHost(),
            'port'   => $this->instance->getPort(),
        ));
    }
401572
def _connect(self):
        """"""
        self._soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._soc.connect((self._ipaddr, self._port))
        self._soc.send(_build_request({'cmd': cmd.CMD_MESSAGE_PASSWORD,
                                       'sha': self._password}))
819535
def connect(self, server, port=6667):
        
        self.socket.connect((server, port))
        self.lines = self._read_lines()
        for event_handler in list(self.on_connect):
            event_handler(self)
1151924
public function connect()
    {
        $this->connection = ftp_connect($this->host);
        if (ftp_login($this->connection, $this->username, $this->password)) {
            if (ftp_chdir($this->connection, $this->getChdir()) && ftp_pasv($this->connection, $this->passive)) {
                $this->connected = true;
                return true;
            }
        }
        return false;
    }
1092596
def connect(self, host=None, port=None):
        """"""
        host = self.host if host is None else host
        port = self.port if port is None else port
        self.socket.connect(host, port)
1140835
def connect(self):
        
        self._build_socket()
        self._connect_socket()
        self._build_file_socket()
        self._send_connect_msg()
1299440
public function connect()
  {
    if($this->stream !== null) return;

    $host = strval($this->config["host"]);
    $port = strval($this->config["port"]);

    $address = "tcp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
    $options = empty($this->config["tls"]) ? array() : array("ssl" => array("allow_self_signed" => TRUE, "verify_peer" => FALSE, "verify_peer_name" => FALSE));
    $timeout = (int) $this->config["timeout"];

    $this->stream = @stream_socket_client($address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options));

    if($this->stream === FALSE)
    {
      throw new Exception(Str::factory($errstr)->toUtf8()->toString(), $errno);
    }

    if(!empty($this->config["tls"]))
    {
      stream_socket_enable_crypto($this->stream, TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
    }

    @stream_set_timeout($this->stream, $timeout);
    @stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0);
  }
1151151
function connect() {
    if (!redis) {
      debug('createClient ' + key + ' at ' + host + ':' + port);
      redis = redisLib.createClient(port, host, redisOpts); }
  }
204232
public function connect()
    {
        if ($this->connected === true) {
            return;
        }
        if ($this->_contextOption) {
            $context = stream_context_create($this->_contextOption);
            $this->_socket = stream_socket_client("udp://{$this->_remoteAddress}", $errno, $errmsg,
                30, STREAM_CLIENT_CONNECT, $context);
        } else {
            $this->_socket = stream_socket_client("udp://{$this->_remoteAddress}", $errno, $errmsg);
        }

        if (!$this->_socket) {
            Worker::safeEcho(new \Exception($errmsg));
            return;
        }
        
        stream_set_blocking($this->_socket, false);
        
        if ($this->onMessage) {
            Worker::$globalEvent->add($this->_socket, EventInterface::EV_READ, array($this, 'baseRead'));
        }
        $this->connected = true;
        // Try to emit onConnect callback.
        if ($this->onConnect) {
            try {
                call_user_func($this->onConnect, $this);
            } catch (\Exception $e) {
                Worker::log($e);
                exit(250);
            } catch (\Error $e) {
                Worker::log($e);
                exit(250);
            }
        }
    }
240885
def connect(self):
        
        # TODO: local_hostname should be configurable
        self.client = smtplib.SMTP(self.options['server'], self.options['port'],
                                   local_hostname='local.domain', timeout=15)
648118
private function connect()
    {
        if (!$this->_sock) {
            if ($this->_persistentSocket) {
                $this->_sock = pfsockopen($this->_host, $this->_port, $errno, $errstr, $this->_connectTimeout/1000);
            } else {
                $this->_sock = fsockopen($this->_host, $this->_port, $errno, $errstr, $this->_connectTimeout/1000);
            }

            if (!$this->_sock) {
                throw new \Exception('Unable to connect to FastCGI application: ' . $errstr);
            }

            if (!$this->set_ms_timeout($this->_readWriteTimeout)) {
                throw new \Exception('Unable to set timeout on socket');
            }
        }
    }
1011574
public function connect()
    {
        $this->socket = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);

        if (!$this->socket) {
            $this->lastResponse = $errstr;
            return false;
        }

        //set timeout
        stream_set_timeout($this->socket, 3, 0);

        // check authorization
        return $this->authorize();
    }