<?php
require 'vendor/autoload.php';
use phpseclib3\Net\SSH2;
use phpseclib3\Net\SFTP;
class ogcp_ssh2 {
private $ssh;
private $sftp;
private $error;
public function __construct() {
$this->ssh = null;
$this->sftp = null;
$this->error = "";
}
public function Connect($host, $port = 22) {
if ($host == "") return false;
$this->ssh = new SSH2($host, $port);
return true;
}
public function ConnectwAuth($host, $port = 22, $user, $pass) {
if ($host == "" || $user == "" || $pass == "") return false;
if ($this->Connect($host, $port)) {
if ($this->ssh->login($user, $pass)) {
return true;
} else {
$this->error = 'Error #02: Authentication rejected by server!';
return false;
}
}
$this->error = 'Error #01: Server not found!';
return false;
}
public function OpenSFTP() {
if (!$this->ssh) return false;
$this->sftp = new SFTP($this->ssh->getHost());
return $this->sftp->login($this->ssh->getUsername(), $this->ssh->getPassword());
}
public function SFTP_DownloadFile($remote, $local) {
if (!$this->sftp) return false;
return file_put_contents($local, $this->sftp->get($remote));
}
public function SFTP_UploadFile($local, $remote) {
if (!$this->sftp) return false;
return $this->sftp->put($remote, file_get_contents($local));
}
public function SFTP_ReadFile($filepath) {
if (!$this->sftp) return false;
return $this->sftp->get($filepath);
}
public function Exec($cmd) {
if (!$this->ssh) return false;
return $this->ssh->exec($cmd);
}
public function Disconnect() {
$this->ssh = null;
$this->sftp = null;
}
}
?>Birde bunu deneyin
sftpfilelink eksik onuda eklermisiniz