// /core/php/sftp/connector.php
session_start();
require_once __DIR__ . '/../../config.php';
require_once __DIR__ . '/../../lib/SFTPClient.php';
$user = $_SESSION['username'] ?? null;
if (!$user) {
echo json_encode(["success" => false, "message" => "Not logged in"]);
exit;
}
// Connect to user's isolated SFTP account
$client = new SFTPClient($SFTP_HOST, $SFTP_PORT, $user, $SFTP_PASSWORD);
$path = $_POST['path'] ?? '/';
$list = $client->listDirectory($path);
echo json_encode(["success" => true, "data" => $list]);