Trying to connect using ssh2_auth_pubkey_file()

前端 未结 3 2247
离开以前
离开以前 2021-02-20 11:16

I am trying to make a php script that runs on the terminal that would connect to a remote server by ssh and retrieve a file. this is my code so far

#!/usr/bin/ph         


        
3条回答
  •  不思量自难忘°
    2021-02-20 11:55

    this looks like the error right here. FILE is a filepath isn't it? so it looks something like /somedir/somefile.php and all you have done is add a / on the end of .php so I don't think this is really valid. see http://www.php.net/manual/en/language.constants.predefined.php

    $cwd = dirname(__FILE__).'/';
    

    also, other people have been having problems with ssh2_auth_pubkey_file returning false under all conditions. you may want to submit a bug report. I was hoping to use this function. I don't know how to use it because I have no idea how to supply a private key.

    I think the code you want is

    if (!defined('__DIR__')) {
        $iPos = strrpos(__FILE__, "/");
        define("__DIR__", substr(__FILE__, 0, $iPos) . "/");
    }
    $cwd=__DIR__ . '/';
    

    and keep in mind that when it comes to the remote directory, you should be using ssh2_sftp_realpath().

    dirname() has been reported to be unreliable.

提交回复
热议问题