Files
USB-RAID-Array/Web/betatest/content/ftp/config.php

35 lines
842 B
PHP
Raw Normal View History

2025-04-14 10:26:56 +02:00
<?php
require '../../vendor/autoload.php';
use phpseclib3\Net\SFTP;
$defPath = $_SESSION['defPath'] ?? '/';
// SFTP Configuration
$host = 'localhost';
$username = 'UNAME';
$password = 'PSWD';
$defaultPath = $defPath;
function initializeSFTP($host, $username, $password) {
$sftp = new SFTP($host);
if (!$sftp->login($username, $password)) {
die('Login Failed');
}
return $sftp;
}
function normalizePath($path) {
$parts = array_filter(explode('/', $path), fn($part) => $part !== '' && $part !== '.');
$stack = [];
foreach ($parts as $part) {
if ($part === '..') {
array_pop($stack);
} else {
$stack[] = $part;
}
}
return '/' . implode('/', $stack);
}
$sftp = initializeSFTP($host, $username, $password);
$currentPath = normalizePath($defaultPath);