0

i am working on ssh2 key authentication in key authentication the function file_get_contents() showing the error,

here is the code

 $name = $_FILES["file"] ["name"];
    if($typer == 'start'){
    
    $ssh = new Net_SSH2($host);
    $key = new Crypt_RSA();
    $key->loadKey(file_get_contents($name));
    if (!$ssh->login($username, $key)) {
        echo json_encode(array("code" =>"400", "message" => "Login Error"));
    }    $name = $_FILES["file"] ["name"];
    
    if($typer == 'start'){
    
    $ssh = new Net_SSH2($host);
    $key = new Crypt_RSA();
    $key->loadKey(file_get_contents($name));
    if (!$ssh->login($username, $key)) {
        echo json_encode(array("code" =>"400", "message" => "Login Error"));
    }

showing error

file_get_contents(id_rsa): failed to open stream: No such file or directory in ssh configuration

Ajmal
  • 99
  • 1
  • 6
  • 1
    `$_FILES["file"]["name"]` is just the name of the file. Try `$_FILES["file"]["tmp_name"]` for its actual path on the server after it's uploaded. – Jeto Apr 02 '21 at 13:36
  • i have to move the file in a folder first, Now this error solved but Login failed statut showing without any error, anyone have any idea about this? – Ajmal Apr 02 '21 at 14:52
  • You only need to move it if you want to store it. If you just need to get its contents right after it's uploaded, then you don't have to. – Jeto Apr 02 '21 at 14:53

0 Answers0