dqjgf0982 2012-07-09 11:55
浏览 424
已采纳

ssh2_connect导致错误324(net :: ERR_EMPTY_RESPONSE):

While trying to list the files present in a remote sftp location using php, I get this error:

Error 324 (net::ERR_EMPTY_RESPONSE):

The server closed the connection without sending any data. On my another lamp server the same code works fine. Please point where I am missing something if you can help please. Thanks in advance.

function listBuildFiles() {

global $sftp_host, $sftp_username, $sftp_password, $sftp_path;
$connection = ssh2_connect($sftp_host);
// Authenticate
if (!ssh2_auth_password($connection, $sftp_username, $sftp_password)) {
    throw new Exception('Unable to connect.');
}

// Create our SFTP resource
if (!$sftp = ssh2_sftp($connection)) {
    throw new Exception('Unable to create SFTP connection.');
}

/**
 * Now that we have our SFTP resource, we can open a directory resource
 * to get us a list of files. Here we will use the $sftp resource in
 * our address string as I previously mentioned since our ssh2://
 * protocol allows it.
 */
$files = array();
$dirHandle = opendir("ssh2.sftp://$sftp$sftp_path");
    $i=0;
// Properly scan through the directory for files, ignoring directory indexes (. & ..)
while (false !== ($file = readdir($dirHandle))) {
    if ($file != '.' && $file != '..') {
        $files[$i] = $file;
        $i++;
    }
}

echo '<select name="buildName">';
echo '<option>Please Select a build</option>';
foreach ($files as $filename) {
      echo "<option value=\"$filename\">$filename</option>";
    }
echo '</select>';
ssh2_exec($connection, "exit");

Thanks, Ujjwal

  • 写回答

2条回答 默认 最新

  • dshu1235 2012-07-10 21:44
    关注

    With phpseclib, a pure PHP SFTP implementation, you can see the full logs of what's going on. Example:

    <?php
    include('Net/SFTP.php');
    
    define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
    
    $sftp = new Net_SFTP('www.domain.tld');
    if (!$sftp->login('username', 'password')) {
        exit('Login Failed');
    }
    
    // puts a three-byte file named filename.remote on the SFTP server
    $sftp->put('filename.remote', 'xxx');
    
    echo $ssh->getLog();
    print_r($ssh->getErrors());
    ?>
    

    The developer of phpseclib is pretty proactive about providing support too so if you can't figure it out from the logs or error messages (s)he probably can.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示