ssh2_scp_send - 将整个本地文件夹内容上载到远程文件夹

I would like to use the ssh2_scp_send function to copy all the contents of a local folder to a folder on the remote computer.

I tried to do the way it shows in the example of the link below, but from what I realized I only copy file to file. http://php.net/manual/pt_BR/function.ssh2-scp-send.php

<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
?>

I thought I'd put this together with a function that lists all the files and subfolders in a parent folder.

function listFolderFiles($dir){
    $ffs = scandir($dir);

    unset($ffs[array_search('.', $ffs, true)]);
    unset($ffs[array_search('..', $ffs, true)]);

    // prevent empty ordered elements
    if (count($ffs) < 1)
        return;

    echo '<ol>';
    foreach($ffs as $ff){
        echo '<li>'.$ff;
        if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);
        echo '</li>';
    }
    echo '</ol>';
}

listFolderFiles('Main Dir');

Source: https://stackoverflow.com/a/7121809/8442925

How could I redo this function above and include the ssh2_scp_send part? Could you give me a north or another method?