Answer the question
In order to leave comments, you need to log in
How to work with sftp from php with authorization using a private SSH-2 RSA key?
I can’t figure it out, basically everything I find points to
https://github.com/phpseclib/phpseclib
however it has some insane documentation, examples from which do not work (errors, or they are from a different version).
I'm trying to do so
<?php
include 'vendor/autoload.php';
$loader = new \Composer\Autoload\ClassLoader();
$loader->addPsr4('phpseclib\\', __DIR__ . 'vendor/phpseclib');
$loader->register();
use phpseclib\Crypt\RSA;
use phpseclib\Net\SSH2;
use phpseclib\Net\SFTP;
$key = new RSA();
$key->setPassword('***');
$key->load(file_get_contents('****.ppk'));
// Domain can be an IP too
$ssh = new SFTP('***',22);
if (!$ssh->login('***', $key)) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
This service allows sftp connections only. This service allows sftp connections only.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question