我用以下ssh2函数成功连接了sftp,也可以正常操作,但是我找不到手动断开的函数,这样的话只能等超时,会给sftp 
服务器带来负担@ssh2_connect($host, $port);
@ssh2_auth_password($this->connection, $username, $password))
@ssh2_sftp($this->connection);有没有办法等我操作完了直接关闭连接?

解决方案 »

  1.   

    PHP脚本的特点,估计执行完就自动关闭了吧。
    类似于数据库的连接?
      

  2.   

    手册里有callback,没用过,不了解具体情况。
    <?php
    /* Notify the user if the server terminates the connection */
    function my_ssh_disconnect($reason, $message, $language) {
      printf("Server disconnected with reason code [%d] and message: %s\n",
             $reason, $message);
    }$methods = array(
      'kex' => 'diffie-hellman-group1-sha1',
      'client_to_server' => array(
        'crypt' => '3des-cbc',
        'comp' => 'none'),
      'server_to_client' => array(
        'crypt' => 'aes256-cbc,aes192-cbc,aes128-cbc',
        'comp' => 'none'));$callbacks = array('disconnect' => 'my_ssh_disconnect');$connection = ssh2_connect('shell.example.com', 22, $methods, $callbacks);
    if (!$connection) die('Connection failed');
    ?> 
      

  3.   

    你说的ssh是什么啊?不是strut+spring+hibernate?那玩意不是Java里的吗?
      

  4.   

    自己顶2楼的那个 也没断开操作啊?  难道真的是php自己断的?
      

  5.   

    ssh2_exec($connection, 'exit');  ?