<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.ssh2.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.ssh2-connect.php',
    1 => 'ssh2_connect',
    2 => 'Connect to an SSH server',
  ),
  'up' => 
  array (
    0 => 'ref.ssh2.php',
    1 => 'SSH2 Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.ssh2-auth-pubkey-file.php',
    1 => 'ssh2_auth_pubkey_file',
  ),
  'next' => 
  array (
    0 => 'function.ssh2-disconnect.php',
    1 => 'ssh2_disconnect',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/ssh2/functions/ssh2-connect.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.ssh2-connect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ssh2_connect</h1>
  <p class="verinfo">(PECL ssh2 &gt;= 0.9.0)</p><p class="refpurpose"><span class="refname">ssh2_connect</span> &mdash; <span class="dc-title">Connect to an SSH server</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.ssh2-connect-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ssh2_connect</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$host</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$port</code><span class="initializer"> = 22</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$methods</code><span class="initializer"> = ?</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$callbacks</code><span class="initializer"> = ?</span></span><br>): <span class="type"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   Establish a connection to a remote SSH server.
  </p>
  <p class="simpara">
   Once connected, the client should verify the server&#039;s hostkey using
   <span class="function"><a href="function.ssh2-fingerprint.php" class="function">ssh2_fingerprint()</a></span>, then authenticate using either
   password or public key.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ssh2-connect-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <dl>
   
    <dt><code class="parameter">host</code></dt>
    <dd>
     <span class="simpara">
     </span>
    </dd>
   
   
    <dt><code class="parameter">port</code></dt>
    <dd>
     <span class="simpara">
     </span>
    </dd>
   
   
    <dt><code class="parameter">methods</code></dt>
    <dd>
     <span class="simpara">
      <code class="parameter">methods</code> may be an associative array with up to four parameters
      as described below.
     </span>
     <table class="doctable table">
      <caption><strong><code class="parameter">methods</code> may be an associative array
             with any or all of the following parameters.</strong></caption>
      
       <thead>
        <tr>
         <th>Index</th>
         <th>Meaning</th>
         <th>Supported Values*</th>
        </tr>

       </thead>

       <tbody class="tbody">
        <tr>
         <td>kex</td>
         <td>
          List of key exchange methods to advertise, comma separated
          in order of preference.
         </td>
         <td>
          <code class="literal">diffie-hellman-group1-sha1</code>,
          <code class="literal">diffie-hellman-group14-sha1</code>, and
          <code class="literal">diffie-hellman-group-exchange-sha1</code>
         </td>
        </tr>

        <tr>
         <td>hostkey</td>
         <td>
          List of hostkey methods to advertise, comma separated
          in order of preference.
         </td>
         <td>
          <code class="literal">ssh-rsa</code> and
          <code class="literal">ssh-dss</code>
         </td>
        </tr>

        <tr>
         <td>client_to_server</td>
         <td>
          Associative array containing crypt, compression, and
          message authentication code (MAC) method preferences
          for messages sent from client to server.
         </td>
         <td class="empty">&nbsp;</td>
        </tr>

        <tr>
         <td>server_to_client</td>
         <td>
          Associative array containing crypt, compression, and
          message authentication code (MAC) method preferences
          for messages sent from server to client.
         </td>
         <td class="empty">&nbsp;</td>
        </tr>

       </tbody>
      
     </table>

     <span class="simpara">
      * - Supported Values are dependent on methods supported by underlying library.
      See <a href="http://libssh2.org/" class="link external">&raquo;&nbsp;libssh2</a> documentation for additional
      information.
     </span>
     <table class="doctable table">
      <caption><strong>
       <code class="parameter">client_to_server</code> and
       <code class="parameter">server_to_client</code> may be an associative array
       with any or all of the following parameters.
      </strong></caption>
      
       <thead>
        <tr>
         <th>Index</th>
         <th>Meaning</th>
         <th>Supported Values*</th>
        </tr>

       </thead>

       <tbody class="tbody">
        <tr>
         <td>crypt</td>
         <td>List of crypto methods to advertise, comma separated
          in order of preference.</td>
         <td>
          <code class="literal">rijndael-cbc@lysator.liu.se</code>,
          <code class="literal">aes256-cbc</code>,
          <code class="literal">aes192-cbc</code>,
          <code class="literal">aes128-cbc</code>,
          <code class="literal">3des-cbc</code>,
          <code class="literal">blowfish-cbc</code>,
          <code class="literal">cast128-cbc</code>,
          <code class="literal">arcfour</code>, and
          <code class="literal">none**</code>
         </td>
        </tr>

        <tr>
         <td>comp</td>
         <td>List of compression methods to advertise, comma separated
          in order of preference.</td>
         <td>
          <code class="literal">zlib</code> and
          <code class="literal">none</code>
         </td>
        </tr>

        <tr>
         <td>mac</td>
         <td>List of MAC methods to advertise, comma separated
          in order of preference.</td>
         <td>
          <code class="literal">hmac-sha1</code>,
          <code class="literal">hmac-sha1-96</code>,
          <code class="literal">hmac-ripemd160</code>,
          <code class="literal">hmac-ripemd160@openssh.com</code>, and
          <code class="literal">none**</code>
         </td>
        </tr>

       </tbody>
      
     </table>

     <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
      <strong>Crypt and MAC method &quot;<code class="literal">none</code>&quot;</strong><br />
      <span class="simpara">
       For security reasons, <code class="literal">none</code> is disabled by the underlying
       <a href="http://libssh2.org/" class="link external">&raquo;&nbsp;libssh2</a> library unless explicitly enabled
       during build time by using the appropriate ./configure options.  See documentation
       for the underlying library for more information.
      </span>
     </p></blockquote>
    </dd>
   
   
    <dt><code class="parameter">callbacks</code></dt>
    <dd>
     <p class="para">
      <code class="parameter">callbacks</code> may be an associative array with any
      or all of the following parameters.
      <table class="doctable table">
       <caption><strong>
        Callbacks parameters
       </strong></caption>
       
        <thead>
         <tr>
          <th>Index</th>
          <th>Meaning</th>
          <th>Prototype</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>ignore</td>
          <td>
           Name of function to call when an
           <strong><code>SSH2_MSG_IGNORE</code></strong> packet is received
          </td>
          <td>void ignore_cb($message)</td>
         </tr>

         <tr>
          <td>debug</td>
          <td>
           Name of function to call when an
           <strong><code>SSH2_MSG_DEBUG</code></strong> packet is received
          </td>
          <td>void debug_cb($message, $language, $always_display)</td>
         </tr>

         <tr>
          <td>macerror</td>
          <td>
           Name of function to call when a packet is received but the
           message authentication code failed.  If the callback returns
           <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, the mismatch will be ignored, otherwise the connection
           will be terminated.
          </td>
          <td>bool macerror_cb($packet)</td>
         </tr>

         <tr>
          <td>disconnect</td>
          <td>
           Name of function to call when an
           <strong><code>SSH2_MSG_DISCONNECT</code></strong> packet is received
          </td>
          <td>void disconnect_cb($reason, $message, $language)</td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ssh2-connect-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="simpara">
   Returns a resource on success, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on error.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ssh2-connect-examples">
  <h3 class="title">Beispiele</h3>
  <div class="example" id="example-1">
   <p><strong>Beispiel #1 <span class="function"><strong>ssh2_connect()</strong></span> example</strong></p>
   <div class="example-contents"><p>
    Open a connection forcing 3des-cbc when sending packets, any strength
    aes cipher when receiving packets, no compression in either direction,
    and Group1 key exchange.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* Notify the user if the server terminates the connection */<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">my_ssh_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$reason</span><span style="color: #007700">, </span><span style="color: #0000BB">$message</span><span style="color: #007700">, </span><span style="color: #0000BB">$language</span><span style="color: #007700">) {<br />  </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Server disconnected with reason code [%d] and message: %s\n"</span><span style="color: #007700">,<br />         </span><span style="color: #0000BB">$reason</span><span style="color: #007700">, </span><span style="color: #0000BB">$message</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$methods </span><span style="color: #007700">= array(<br />  </span><span style="color: #DD0000">'kex' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'diffie-hellman-group1-sha1'</span><span style="color: #007700">,<br />  </span><span style="color: #DD0000">'client_to_server' </span><span style="color: #007700">=&gt; array(<br />    </span><span style="color: #DD0000">'crypt' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'3des-cbc'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'comp' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'none'</span><span style="color: #007700">),<br />  </span><span style="color: #DD0000">'server_to_client' </span><span style="color: #007700">=&gt; array(<br />    </span><span style="color: #DD0000">'crypt' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'aes256-cbc,aes192-cbc,aes128-cbc'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'comp' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'none'</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">$callbacks </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'disconnect' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'my_ssh_disconnect'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$connection </span><span style="color: #007700">= </span><span style="color: #0000BB">ssh2_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'shell.example.com'</span><span style="color: #007700">, </span><span style="color: #0000BB">22</span><span style="color: #007700">, </span><span style="color: #0000BB">$methods</span><span style="color: #007700">, </span><span style="color: #0000BB">$callbacks</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$connection</span><span style="color: #007700">) die(</span><span style="color: #DD0000">'Connection failed'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ssh2-connect-seealso">
  <h3 class="title">Siehe auch</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.ssh2-fingerprint.php" class="function" rel="rdfs-seeAlso">ssh2_fingerprint()</a> - Retrieve fingerprint of remote server</span></li>
   <li><span class="function"><a href="function.ssh2-auth-none.php" class="function" rel="rdfs-seeAlso">ssh2_auth_none()</a> - Authenticate as &quot;none&quot;</span></li>
   <li><span class="function"><a href="function.ssh2-auth-password.php" class="function" rel="rdfs-seeAlso">ssh2_auth_password()</a> - Authenticate over SSH using a plain password</span></li>
   <li><span class="function"><a href="function.ssh2-auth-pubkey.php" class="function" rel="rdfs-seeAlso">ssh2_auth_pubkey()</a> - Authenticate using a public key in a variable</span></li>
   <li><span class="function"><a href="function.ssh2-auth-pubkey-file.php" class="function" rel="rdfs-seeAlso">ssh2_auth_pubkey_file()</a> - Authenticate using a public key read from a file</span></li>
   <li><span class="function"><a href="function.ssh2-disconnect.php" class="function" rel="rdfs-seeAlso">ssh2_disconnect()</a> - Close a connection to a remote SSH server</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>