PHPSECLIB file upload with progress

$sftp->put($to, $from, NET_SFTP_LOCAL_FILE);

How to display a real-time progress bar using phpseclib put?
I already did, while uploading sending ajax with interval to check the file size.

Does someone have better idea how to do it?

Thanks a lot for your help!

phpseclib 1.0.x:

$sftp->put('filename.ext', str_repeat('a', 1024 * 1024), NET_SFTP_STRING, -1, -1, function($sent) {
    echo "sent: $sent/n";
});

phpseclib 2.0.x:

$sftp->put('filename.ext', str_repeat('a', 1024 * 1024), SFTP::SOURCE_STRING, -1, -1, function($sent) {
    echo "sent: $sent/n";
});