Login   Register  
PHP Classes

File: examples/kernel/net/TFTPHandler/authenticateWithKey.php

Recommend this page to a friend!
  Classes of ASCOOS CMS   Ascoos OS   examples/kernel/net/TFTPHandler/authenticateWithKey.php   Download  
File: examples/kernel/net/TFTPHandler/authenticateWithKey.php
Role: Example script
Content typex: text/plain
Description: Example script
Class: Ascoos OS
A PHP Web 5.0 Kernel for decentralized web and IoT
Author: By
Last change: Update of examples/kernel/net/TFTPHandler/authenticateWithKey.php
Date: 1 month ago
Size: 2,010 bytes
 

Contents

Class file image Download
<?php
/**
 * @ASCOOS-NAME : Ascoos OS
 * @ASCOOS-VERSION : 26.0.0
 * @ASCOOS-SUPPORT : [email protected]
 * @ASCOOS-BUGS : https://issues.ascoos.com
 *
 * @desc <English> Demonstrates SFTP authentication using public/private key with the authenticateWithKey method.
 * @desc <Greek> ??????????? ??? ??????????? SFTP ?? ???????/???????? ?????? ??????????????? ?? ?????? authenticateWithKey.
 *
 * @since PHP 8.2.0
 */

use ASCOOS\OS\Kernel\Net\TFTPHandler;

global
$conf, $AOS_CACHE_PATH, $AOS_SSL_PATH;

// <English> Initialize properties array with configuration
// <Greek> ???????????? ?????? ????????? ?? ??????????
$properties = [
   
'ftp' => [
       
'protocol' => 'sftp',
       
'host' => 'example.com',
       
'port' => 22,
       
'publicKey' => $conf['ssl']['paths']['public'] . '/public.key' ?? $AOS_SSL_PATH . '/public/public.key',
       
'privateKey' => $conf['ssl']['paths']['private'] . '/private.key' ?? $AOS_SSL_PATH . '/private/private.key'
   
],
   
'logs' => ['useLogger' => true, 'dir' => $AOS_LOGS_PATH],
   
'cache' => ['cacheType' => 'file', 'cachePath' => $AOS_CACHE_PATH]
];

// <English> Create a new TFTPHandler instance
// <Greek> ?????????? ???? instance ??? TFTPHandler
$ftpHandler = new TFTPHandler($properties);

// <English> Connect to the server
// <Greek> ??????? ???? ??????????
$ftpHandler->connect('example.com', 22);

// <English> Authenticate with key
// <Greek> ??????????? ?? ??????
if ($ftpHandler->authenticateWithKey('user', $AOS_SSL_PATH . '/public/public.key', $AOS_SSL_PATH . '/private/private.key', '')) {
    echo
"Authenticated successfully with key\n";
} else {
    echo
"Authentication failed\n";
}

// <English> Free resources
// <Greek> ???????????? ?????
$ftpHandler->Free($ftpHandler);
?>